Take the 2-minute tour ×

I'm executing this code:

p = subprocess.Popen(['/path/to/my/script.sh','--flag'] , stdin=subprocess.PIPE)

It works when executing it on the shell using "python scriptName.py", BUT when executing using PyDev in Eclipse, it fails, the reason:

/path/to/my/script.sh: line 111: service: command not found

This bash script "script.sh" contains the following command which causes the error:

service mysqld restart

So "service" is not recognized when running the .sh script from the context of PyDev. I guess it has to do with some ENV VAR configurations, couldn't find how to do it.

  • BTW - Using "shell=True" when calling subprocess.Popen didn't solve it.
share|improve this question
Which OS are you using (enviroment variable setting and where to set differs) –  Mark Apr 20 '13 at 21:57
I use Red Hat 5 –  GilM Apr 20 '13 at 22:05
add comment

1 Answer

service usually is located in /usr/sbin, and that this directory isn't on the PATH. As this usually contains administrative binaries and scripts which arn't designed to be run by everyone (only by admins/root), the sbin directories arn't always added to the PATH by default.

To check this, try to print PATH in your script (or add an env command).

To fix it, you could either

  • set the PATH in your python script using os.setenv
  • pass an env dict containing the correct PATH to Popen
  • set the PATH in your shellscript
  • use the full path in your shellscript
  • set the PATH in eclipse
share|improve this answer
add comment

Your Answer


