简体   繁体   English

为什么/ usr / local / bin在我的C ++程序中无法识别?

[英]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.

相关问题 为什么我的python可执行文件不默认为/ usr / local / bin? - Why my python executable does not default to /usr/local/bin? 为什么软件包没有安装到我的 Mac 上的两个版本 Python(在 /User/name/Library 和 /usr/local/bin 中)? - Why are packages not installing to both versions of Python on my Mac (in /User/name/Library and /usr/local/bin)? 哪个版本的程序会执行? / usr / bin中的那个或/ usr / local / bin中的那个? - which version of program will execute? the one in the /usr/bin or the one in /usr/local/bin? 在Mac OSX 10.6.8上从usr / local / bin安全删除程序吗? - Safely removing program from usr/local/bin on Mac OSX 10.6.8? 为什么使用/ usr / bin / env会破坏我的Python导入? - Why does using /usr/bin/env break my Python import? / usr / bin / python vs / usr / local / bin / python - /usr/bin/python vs /usr/local/bin/python 在/ usr / bin而非/ usr / local / bin中安装pip - Installing pip in /usr/bin instead of /usr/local/bin 默认python / usr / bin / python而不是/ usr / local / bin / python - Default python /usr/bin/python instead of /usr/local/bin/python 我如何将一个带有多个文件的python程序放在/ usr / local / bin中? - How can I put a python program with multiple files in /usr/local/bin? 来自/ usr / local / bin /目录的相对路径 - Relative path from the /usr/local/bin/ directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM