Windows上の別のプログラムからSASプログラムを呼びたいと思っています。コマンドラインからバッチモードでSASを呼び出す経験はありますが、メッセージを受け取ってそのメッセージを処理する実際の経験はありません。私は、SASプログラムの中からstdinからの読み方についてかなりの情報を見つけましたが、私のSASプログラムをstdoutまたはstderrに書き出す方法を理解できていないようです。 Windowsでこれを行うことはできますか?WindowsのSASからstdoutとstderrをキャプチャしますか?
SASプログラムから、私は次の操作を行いたいと思います:
- は手動でエラーを検出し、SASプログラム内でログファイル
- にそれらを印刷するのではなく、stderrに警告メッセージとエラーメッセージをリダイレクトしますおよび/またはその他の問題を検出し、stderrまたはstdoutに出力します。 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;
の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()
私の結果をされています。ここ
は、私が試したものである
('', '')
私はSASを一度も使用していませんが、コンソールアプリケーションですか? stdout/stderrのハンドルがないかもしれません。その場合、PyWin32の 'win32com'モジュールを使って[SAS using OLE](http://support.sas.com/documentation/cdl/en/hostwin/63285/HTML/default/viewer.htm#oleauto.htm)を試してください。 – eryksun
有用な名前のついたパイプの使用に関するSASの文書へのリンクは次のとおりです。 http://support.sas.com/documentation/cdl/en/hostwin/63285/HTML/default/viewer.htm#unnamed.htm興味深いのは – RWill