Python Forum

Full Version: Python and bash command confusion
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
If from my bash cursor I do:
#pgrep myproces
nothing is returned as the process isn't running.

If from another server I do the following:
ssh [email protected] pgrep myprocess
nothing is returned, correctly.

If from my python code I do:
ir = os.popen("rsh [email protected] pgrep myprocess").readline()
print ir
10734 <<<< Whaaat? Why?

Then if I pgrep myprocews again nothing is returned.
I do the python line again and I get a pid, but a new pid.

So it looks as if, for some reason os.popen.... makes up a pid when there isn't a pid to return. But this is running a bash command which itself wont do this, so what on earth is going on here? If I run the python code on a process name that doesn't exist it correctly returns nothing. I'm very confused.

I need a way around this as it makes this os call completely unreliable. Could someone please let me know whets going on here?

Many thanks.