我正在尝试使用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]
因为我没有找到任何autoexec文件,所以我不包括SAS的autoexec_path。如果我有autoexec文件,
self.cmd = [sas_path,'-config',sas_config_path,'-autoexec',autoexec_path,'-sysin',sas_code_path]
问题是SAS代码成功执行,但是proc.returncode
不等于0。因此,我的python代码不知道该代码成功运行。我有做错什么吗?
您可能在日志中有警告。
从文档中,"SAS® 9.4 Companion for Windows, Fifth Edition"
返回码和完成状态
在Windows批处理变量ERRORLEVEL中返回用于完成SAS作业的返回码。
…
ERRORLEVEL变量的值