[英]Why /usr/local/bin is not recognisable in my C++ program?
My C++ code: 我的C ++代码:
int main(int argc, const char * argv[])
{
system("python test.py");
return 0;
}
I have a program foo
in /usr/local/bin, and I can just type foo
in Unix console and it starts. 我在/ usr / local / bin中有一个程序
foo
,我可以在Unix控制台中输入foo
然后启动它。
The following Python script (test.py) works: 以下Python脚本(test.py)有效:
from subprocess import call
call(["/usr/local/bin/foo"])
This one doesn't (with a "command not found" error): 这个没有(带有“未找到命令”错误):
from subprocess import call
call(["foo"])
Why is my Python script, when executed from C++, not able to call the program directly? 为什么我的Python脚本在从C ++执行时无法直接调用程序?
EDIT: 编辑:
I'm on Mac OSX. 我在Mac OSX上。 I suspect this has something to do with the folder
/usr/local/bin
not added by the C++ executable or something like that. 我怀疑这与C ++可执行文件中没有添加的文件夹
/usr/local/bin
有关。
EDIT: 编辑:
which kallisto
/usr/local/bin/kallisto
cat test.py
from subprocess import call
call(["kallisto"])
python test.py
kallisto 0.43.0
In my C++ run:
Traceback (most recent call last):
File "/Users/tedwong/Sources/QA/test.py", line 2, in <module>
call(["kallisto"])
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 522, in call
return Popen(*popenargs, **kwargs).wait()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
Thanks to @ilent2, his answer solved my problem. 感谢@ ilent2,他的回答解决了我的问题。 I was using an IDE to run the C++ code and never realised that I had to tell the IDE my paths.
我使用IDE来运行C ++代码,但从未意识到我必须告诉IDE我的路径。 When I ran the same program directly in the console, it worked.
当我直接在控制台中运行相同的程序时,它工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.