Python.Popen () subprocess and source

Third-party Python 2.5 script I'm trying to debug, silenced me. Relevant part of the script:

proc = subprocess.Popen( "ls && source houdini_setup", shell = True, executable = "/bin/bash", ) 

There is a daemon that listens on port 5001 and runs the above script. When the script is executed, it crashes with the following error:

 _cygwin.py houdini_setup ... (more files) ... /bin/sh: line 0: source: houdini_setup: file not found 

There are so many houdini_setup files, as shown in ls, and in fact, if I changed "source" to "cat" in the script above, the script prints the contents of houdini_setup as expected. Moreover, executing the exact command above in the bona-fide bash shell also sends the file without complaint.

Does anyone know what is going on here?

+4
source share
3 answers

source uses $PATH to find what you pass to it if you don't specify a directory. Try source ./houdini_setup .

+7
source

You can use strace to diagnose such problems. In this case, starting with the -ff flag for a subsequent subprocess would indicate that your code looked for "houdini_setup" elsewhere:

 stat64("/usr/local/bin/houdini_setup", 0xbf989e60) = -1 ENOENT (No such file or directory) stat64("/usr/bin/houdini_setup", 0xbf989e60) = -1 ENOENT (No such file or directory) stat64("/bin/houdini_setup", 0xbf989e60) = -1 ENOENT (No such file or directory) 

This could lead to a documentation check for the embedded source .

+2
source

Perhaps you can just use bash to do the job, if available on your system:

 os.popen("/bin/bash -l -c 'source $HOME/.yourfiletobesourced'") 
0
source

All Articles