- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我想从 Windows 上的另一个程序调用 SAS 程序。我有一些以批处理模式从命令行调用 SAS 的经验,但没有从中接收消息和处理这些消息的实际经验。我用谷歌搜索了一下,发现了很多关于从 SAS 程序中从 stdin 读取的信息,但我似乎无法弄清楚如何让我的 SAS 程序写出到 stdout 或 stderr。我什至可以在 Windows 中执行此操作吗?
在 SAS 程序中,我想执行以下操作:
这是我尝试过的:
SAS
data test;
attrib i length=8;
do i = 1 to 10;
put 'putting'; *how can i make this go to stdout?;
putlog 'putting to log'; *this can go to the log - that is okay;
if i = 5 then do;
*pretend this is an error I am manually detecting - how can i make this go to stderr?;
put 'we found 5';
end;
output;
end;
run;
data _null_;
1 = y; *this is an error detected by SAS. How can I make this go to stderr?;
run;
调用 SAS 的 Python:
import subprocess
import os
if __name__ == '__main__':
filename = os.path.normpath(r'C:\Users\oob\Desktop\sas_python_test.sas')
sas_executable = os.path.normpath(r'C:\Program Files\SAS\SASFoundation\9.2\sas.exe')
cmd = r'"' + sas_executable + r'"' + " " + r'"' + filename + r'"'
p = subprocess.Popen(cmd,shell=False,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
print p.communicate()
我在控制台上的结果是:
('', '')
最佳答案
据我所知,这是不可能直接实现的。您可以通过使用 -sysparm 命令行参数将唯一文件名传递到 sas 并将 STDOUT 输出保存到该文件来模拟这一点。然后您可以使用 -log 命令行参数将 sas 日志发送到不同的文件。 SAS 程序完成后,您将能够使用您选择的程序来解析生成的每个文件。不幸的是,日志文件在 sas 程序完成处理之前一直处于锁定状态,因此如果您想使用 SAS 处理日志文件,您将需要启动第二个后续程序来执行此操作。 (即,您无法从创建它的 SAS 程序中读取日志文件)。
一旦您阅读日志,您就可以查找以 ERROR: 或 WARNING: 开头的行,并采取适当的措施(在我的情况下,它会向我发送电子邮件)。您可能想要添加一些适合您的编码风格的逻辑。例如,一些 SAS 视为 NOTES 的东西我认为是 ERRORS。另外,有些 SAS 认为我不关心的错误。这是我使用的逻辑:
data problems log;
length line $1000;
infile "&logfile";
input;
logfile = "&logfile";
line_no = _n_;
line = _infile_;
problem = 0;
if
(
line =: "ERROR:"
or line =: "WARNING:"
or line =: "NOTE: Numeric values have been converted to character values"
or line =: "NOTE: Character values have been converted to numeric values"
or line =: "NOTE: Missing values were generated as a result of performing an operation on missing values"
or line =: "NOTE: MERGE statement has more than one data set with repeats of BY values"
or line =: "NOTE: Invalid (or missing) arguments to the INTNX function have caused the function to return"
or line =: "INFO: Character variables have defaulted to a length of 200"
or line =: "NOTE: Invalid"
)
and not
(
line =: "WARNING: Your system is scheduled to expire"
or line =: "WARNING: The Base Product product with which Session Manager is associated"
or line =: "WARNING: will be expiring soon, and is currently in warning mode to indicate"
or line =: "WARNING: this upcoming expiration. Please run PROC SETINIT to obtain more"
or line =: "WARNING: information on your warning period."
or line =: "WARNING: This CREATE TABLE statement recursively references the target table. A consequence"
or line =: "WARNING: Unable to copy SASUSER registry to WORK registry. Because of this, you will not see registry customizations during this"
or line =: "WARNING: Estimates did not improve after a ridge was encountered in the objective function."
or line =: "WARNING: Estimates may not have converged."
or line =: "ERROR: A lock is not available for"
or line =: "ERROR: Errors printed on pages"
)
then do;
problem = 1;
output problems;
end;
output log;
run;
希望这对您有所帮助。
关于python - 在 Windows 中从 SAS 捕获 stdout 和 stderr?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8234999/
我有以下代码来捕获和处理运行命令输出。 如何修改它以便运行命令窗口显示输出并同时记录输出?更换 @SW_HIDE与 @SW_SHOW (或等效的)只显示一个空白的命令窗口。 类似于linux的东西te
[已编辑] 用于处理 subprocess.Popen 标准输出的 2 个选项是 stdout="a_file_name" 和 stdout=subprocess.PIPE。 stderr 可以通过
c99 的 7.19.3/7 节指出: At program start-up, three text streams are predefined and need not be opened ex
我正在运行以下 proc_open 函数。加载页面时,出现错误: Use of undefined constant STDOUT - assumed 'STDOUT'` 如何正确设置STDOUT和S
我有一个运行多个进程的开发堆栈:网络服务器、自动测试、后台编译等。所有这些都是基本的命令行命令,例如 node app.js 或 lein midje :autotest. 是否可以使用一个脚本在“后
我正在使用 SLURM 在 super 计算机上调度作业。我已设置 --output=log.out 选项,将作业标准输出中的内容放入文件 (log.out)。我发现该文件每 30-60 分钟更新一次
ansible/ansible-playbook 版本:2.1.2.0/2.2.0.0 我正在尝试使用 yum/apt 安装软件包,但由于安装软件包的存储库位于 packagecloud.io 中,有
bala@hp:~$ echo "Hello World" > stdout bala@hp:~$ cat stdout Hello World bala@hp:~$ echo "Hello Worl
在从 Fortran 编写的外部库中调用嘈杂的函数之前,我正在使用如下代码重定向标准输出: // copy standard output out = dup(STDOUT_FILENO); // c
这个问题在这里已经有了答案: How can I pipe stderr, and not stdout? (11 个答案) 关闭 6 年前。 我有一个程序,我想检查其 STDERR 输出并在其上运
我正在从 perl 运行一个 java 应用程序 这是脚本 #!/usr/bin/perl use strict; use warnings; $| = 1; my $args = join (" "
我正在尝试将 python 脚本的 STDOUT 重定向到一个文件。 如果 STDOUT 是从 sys 导入的,脚本的输出不会被重定向到一个文件: from sys import stdout std
我正在尝试使用 PHP 和 Apache(在 Docker 的前台运行)写入 stdout(或 stderr)。 这些作品: file_put_contents( "php://stderr","wo
我正在尝试重定向标准输出,以便 Windows 应用程序中的 printf 将转到我选择的文件。 我这样做: outFile = fopen("log.txt", "w"); *stdout = *o
在 Ruby 中,$stdout(前面有一个美元符号)和 STDOUT(全部大写)有什么区别?在进行输出重定向时,应该使用哪个,为什么? $stderr 和 STDERR 也是如此。 编辑: 刚找到一
让我们看看这个Hello World程序 #include int main(int argc, char ** argv) { printf("Hello, World!"); c
我在 64 位机器上运行 Ubuntu 20.04。 我想将 stdout 重定向到从 memfd_create 获得的描述符。似乎使用 memfd_create 创建的匿名文件只有在 stdout
我想在 Python 脚本末尾捕获控制台输出。也就是说,我既想正常打印到控制台,又想在执行结束时将控制台输出保存到文件中。 我看过各种相关的 SO 问题 1 , 2 , 3尽管他们要么简单地重定向输出
我知道可以将两者都重定向到特定文件: ./command 1> out.log 2> err.log 或 ./command 1>test.log 2>&1 将两者写入文件。但是我不知道在只打印其中一
我知道可以将两者都重定向到特定文件: ./command 1> out.log 2> err.log 或 ./command 1>test.log 2>&1 将两者写入文件。但是我不知道在只打印其中一
我是一名优秀的程序员,十分优秀!