【问题标题】:Invoking SAS script using python - subprocess使用 python 调用 SAS 脚本 - 子进程
【发布时间】: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


【解决方案1】:

日志中可能有警告。

来自文档,"SAS® 9.4 Companion for Windows, Fifth Edition"

返回代码和完成状态

完成 SAS 作业的返回码在 Windows 批处理变量 ERRORLEVEL 中返回。

ERRORLEVEL 变量的值

【讨论】:

  • 谢谢理查德。我的 SAS 代码日志有警告,这就是我收到返回代码 1 的原因。这非常有帮助。
  • 很高兴听到这个消息,欢迎来到 SO。请务必标记您的问题的答案以及您认为有帮助的其他问题的答案。 stackoverflow.com/help/someone-answers
猜你喜欢
  • 2011-11-01
  • 1970-01-01
  • 2012-07-31
  • 2015-07-16
  • 1970-01-01
  • 1970-01-01
  • 2013-09-26
  • 2015-06-10
  • 1970-01-01
相关资源
最近更新 更多