从matlab运行python脚本不起作用,但从终端运行良好

时间:2014-10-25 02:38:42

标签: python matlab system

我有一个python脚本说script.py,我可以从终端调用没问题,在脚本中间使用os.system('unar file')取消归档文件。但是,当尝试使用system('python script.py')从matlab运行此脚本时,它会运行,但是当它到达unar线时,它会指示" sh:unar:command not found"。

这怎么可能?是不是matlab系统命令应该与终端相同?任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:2)

在您的终端中,您的python脚本可以从您的PATH环境中受益,因此它知道/usr/bin/unar应用程序所在的位置。在Matlab中,它没有。您需要为os.system调用提供应用程序和文件的完整路径。

另外,os.system非常糟糕。请改用subprocess.Popen,这样可以重定向sys.stdinsys.stdout

以下是使用subprocesshttps://gist.github.com/voodoonofx/8e5bcae8e0b0c5741148

的要点示例
相关问题