2012-04-09 7 views
0

私はpython subprocess.Popenで立ち往生しています。私はサブプロセスモジュールを経由してpythonからオクターブを呼び出します。

Shell: octave --eval "1+1" 
GNU Octave, version 3.6.1 
Copyright (C) 2012 John W. Eaton and others. 
This is free software; see the source code for copying conditions. 
There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE. For details, type `warranty'. 

Octave was configured for "i686-pc-mingw32". 

Additional information about Octave is available at http://www.octave.org. 

Please contribute if you find this software useful. 
For more information, visit http://www.octave.org/help-wanted.html 

Read http://www.octave.org/bugs.html to learn how to submit bug reports. 

For information about changes from previous versions, type `news'. 

ans = 2 

を取得し、シェルからオクターブを呼び出すとシステムがWindows 7のx64を実行している私が欲しいのは

process = subprocess.Popen(['octave.exe', '--eval "1+1"'], stdout=subprocess.PIPE) 
process.wait() 
print(process.stdout.read()) 

でオクターブ・プロセスを開始することです。しかし、私が得るすべては

octave.exe: unrecognized option '--eval "1+1"' 

usage: octave [-HVdfhiqvx] [--debug] [--echo-commands] [--eval CODE] 
    [--exec-path path] [--help] [--image-path path] [--info-file file] 
    [--info-program prog] [--interactive] [--line-editing] 
    [--no-history] [--no-init-file] [--no-init-path] [--no-line-editing] 
    [--no-site-file] [--no-window-system] [-p path] [--path path] 
    [--silent] [--traditional] [--verbose] [--version] [file] 

です。

答えて

0

"subprocess.list2cmdline"を使用してパスを構築します。スペースと引用符はすべて変換されます。したがって、次の引数リストは正しいです。

args = ["octave.exe", "--eval", '1+1'] 
print(subprocess.list2cmdline(args)) 
関連する問題