【问题标题】:Call octave from python via subprocess module通过 subprocess 模块从 python 调用 octave
【发布时间】:2012-04-09 08:56:59
【问题描述】:

我被困在 python subprocess.Popen。我想要的只是开始八度音程过程

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]

当我从 shell 调用 octave 时,我得到了

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。

【问题讨论】:

    标签: python-2.7 octave subprocess


    【解决方案1】:

    “subprocess.list2cmdline”用于构建路径。任何空格和引号都将被转换。因此下面的参数列表是正确的。

    args = ["octave.exe", "--eval", '1+1']
    print(subprocess.list2cmdline(args))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-07
      • 2020-11-03
      • 2011-09-02
      • 1970-01-01
      • 2014-06-15
      • 2015-10-07
      • 2021-12-15
      • 2015-04-15
      相关资源
      最近更新 更多