Python and bash command confusion - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Python and bash command confusion (/thread-13371.html) |
Python and bash command confusion - MuntyScruntfundle - Oct-11-2018 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. |