The errors you see are related to the fact that you use os.popen() to run the command, which means that the channel opens and connects to the stdout command. Whenever a command (or anything that it executes without redirecting stdout ) wants to write to stdout , it will try to write to the pipe. But you are not holding the phone, since you are not assigning the result of os.popen() anywhere, therefore it is cleared by Python and closed. Thus, processes that try to write to it collide with a broken pipe and cause the error you see. ( os.popen() does not redirect stderr to the channel, so you see errors anyway.)
Another problem in your os.popen() call is that you are not checking to make sure that the directory does not contain characters specific to your shell. If the catalog contains a quote, for example, or *, strange things may arise. Using os.popen() like this is pretty bad.
Instead, you should use subprocess.Popen() and explicitly specify what you want to do with the output of the process (both stdout and stderr.) You pass subprocess.Popen() list of arguments (including what you want to run) instead of one lines, and she generally avoids the shell, does not need common sense - check your lines. If you really want to ignore the conclusion, you would do it with something like:
devnull = open(os.devnull, 'w') for directory in directories: subprocess.Popen(['runtool_exec', directory], stdout=devnull)
although I would highly recommend at least doing some rudimentary checks on the result of the subprocess. Try checking to see if the process terminated prematurely or with an error code.
source share