Why /usr/local/bin is not recognisable in my C++ program?
<p>My C++ code:</p>

<pre><code>int main(int argc, const char * argv[])
{
    system("python test.py");
    return 0;
}
</code></pre>

<p>I have a program <code>foo</code> in /usr/local/bin, and I can just type <code>foo</code> in Unix console and it starts.</p>

<p>The following Python script (test.py) works:</p>

<pre><code>from subprocess import call
call(["/usr/local/bin/foo"])
</code></pre>

<p>This one doesn't (with a "command not found" error):</p>

<pre><code>from subprocess import call
call(["foo"])
</code></pre>

<p>Why is my Python script, when executed from C++, not able to call the program directly?</p>

<p><strong>EDIT:</strong></p>

<p>I'm on Mac OSX. I suspect this has something to do with the folder <code>/usr/local/bin</code> not added by the C++ executable or something like that.</p>

<p><strong>EDIT:</strong></p>

<pre><code> 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 &lt;module&gt;
    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 
</code></pre>

<p>Thanks to @ilent2, his answer solved my problem. I was using an IDE to run the C++ code and never realised that I had to tell the IDE my paths. When I ran the same program directly in the console, it worked.</p>

python c++