tags:

views:

255

answers:

2

A third-party Python 2.5 script I'm trying to debug has got me stymied. The relevant part of the script is:

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

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

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

There very much exists a file houdini_setup, as illustrated by the ls, and in fact if I change "source" to "cat" in the script above, the script prints the contents of houdini_setup as expected. Moreover, running the exact above command in a bona-fide bash shell also sources the file with no complaints.

Does anyone have any idea what's going on here?

+5  A: 

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

Ignacio Vazquez-Abrams
That did the trick, thanks!In a real bash shell, source doesn't need a ./ for files in the current directory, even when $PATH does not include said directory. Any idea why it's needed in Popen()?
It may have to do with the fact that the shell executing was actually sh, not bash, despite the line passed to the function call.
LeafStorm
It has been my experience that it *is* needed. Always.
Ignacio Vazquez-Abrams
Even if it isn't needed, it should be. Having . in the path is a configuration problem, and can lead to all kinds of badness and confusion.
Andrew McGregor
+1  A: 

You can use strace to help diagnose problems like this. In this case running it with the -ff flag to follow subprocess would have revealed that your code was looking for "houdini_setup" in the wrong place:

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)

That could have led you to check the documentation for the source builtin.

daf