使用python子进程调用SAS脚本

2024-10-01 00:19:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用python和subprocess调用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\u路径,因为我没有找到任何autoexec文件。 如果我有autoexec文件

self.cmd = [sas_path,'-config',sas_config_path,'-autoexec',autoexec_path,'-sysin',sas_code_path]

问题是SAS代码执行成功,但是proc.returncode不等于0。因此,我的python代码不知道代码是否成功运行。
我做错什么了吗?你知道吗


Tags: pathselfcmdconfigmessagestatuscodeerror
1条回答
网友
1楼 · 发布于 2024-10-01 00:19:08

日志中可能有警告。你知道吗

从文档中,"SAS® 9.4 Companion for Windows, Fifth Edition"

Return Codes and Completion Status

The return code for the completion of a SAS job is returned in the Windows batch variable, ERRORLEVEL.

Values for the ERRORLEVEL Variable

enter image description here

相关问题 更多 >