简体   繁体   English

python子进程,无此文件或目录

[英]python subprocess, No such file or directory

I have read all related Questions, and haven't found solution. 我已经阅读了所有相关问题,但尚未找到解决方案。 Here's my problem: 这是我的问题:

在此处输入图片说明

It can be seen that cmd gets printed and is correct and when I copy paste it to the terminal, it does the correct job. 可以看到cmd被打印出来并且是正确的,当我将其粘贴到终端时,它可以完成正确的工作。 However, calling it via python with absolute path cannot find the file... 但是,通过带有绝对路径的python调用它找不到文件...

Since you are passing the command as a single string, you need to specify shell=True so that the command line is broken up into the appropriate command name and arguments. 由于您将命令作为单个字符串传递,因此需要指定shell=True以便将命令行分解为适当的命令名称和参数。 However, a better approach is to build the list yourself. 但是,更好的方法是自己构建列表。

cmd = ["glpsol", "-m", os.path.join(os.path.dirname(__file__), "workingLP.txt")]

This avoids the need to escape the spaces in the pathname. 这样避免了对路径名中的空格进行转义的需要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM