python - 使用 python 调用 SAS 脚本 - 子进程
问题描述
我正在尝试使用 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 文件。如果我有 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”
返回代码和完成状态
SAS 作业完成的返回码在 Windows 批处理变量 ERRORLEVEL 中返回。
…
ERRORLEVEL 变量的值
推荐阅读
- woocommerce - 如何获取 woocommerce order rest api 的结帐 url
- marklogic - 重试 Marklogic 触发器
- c# - 一个 if 语句中的多个 Bool 或嵌套?
- node.js - 在提交到矿池之前验证 NodeJS 中的挖矿份额(Stratum)
- java - dcevm 热插拔代理 openjdk 亚马逊 corretto
- spring-webflux - 重试在 Spring Cloud Stream Reactive 中只执行一次
- php - Apache2 子域
- windows - 为什么通过 UWP 下载文件时 $DATA 为空
- python - Python 字典的深度
- c# - 更新 Parallel.ForEach 线程中对象的属性是否安全?