【发布时间】:2019-10-24 10:46:33
【问题描述】:
我正在尝试使用 python 和子进程调用 sas 脚本。这是我的代码:
proc = Popen(self.cmd, shell=True, stdout=PIPE, stderr=STDOUT)
proc.wait()
standard_output, standard_error = proc.communicate()
if proc.returncode == 0:
log.info("Successfully executed execute_shell_command")
elif proc.returncode == 1:
self.status_message = "return code 1 from" + " ".join(self.cmd) + "error msg: " + str(standard_error)
self.flag = 1
raise ValueError(self.status_message)
elif proc.returncode > 1:
self.status_message = "Error occurred while executing command on shell :" + " ".join(self.cmd) + ' ' + standard_error
self.flag = 1
raise ValueError(self.status_message)
self.cmd = [sas_path,'-config',sas_config_path,'-sysin',sas_code_path]
我没有包含 SAS 的 autoexec_path,因为我没有找到任何 autoexec 文件。 如果我有自动执行文件,那么,
self.cmd = [sas_path,'-config',sas_config_path,'-autoexec',autoexec_path,'-sysin',sas_code_path]
问题是SAS代码执行成功,但是proc.returncode不等于0,所以我的python代码不知道代码运行成功。
有什么我做错了吗?
【问题讨论】:
-
你能设置 -log 选项并检查有什么问题吗?
-
我的sas代码发出警告,这就是为什么返回码是1。
标签: python sas subprocess popen