Python Forum
Python and bash command confusion
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python and bash command confusion
#1
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Call a bash script from within a Python programme Pedroski55 6 2,372 Dec-06-2021, 01:53 PM
Last Post: DeaD_EyE
  Showing and saving the output of a python file run through bash Rim 3 2,370 Oct-06-2021, 10:48 AM
Last Post: gerpark
  How to kill a bash script running as root from a python script? jc_lafleur 4 5,786 Jun-26-2020, 10:50 PM
Last Post: jc_lafleur
  python ast if-elif confusion holyghost 3 3,016 Apr-19-2020, 12:36 PM
Last Post: pyzyx3qwerty
  Trying to convert my Expect/bash to Python sumncguy 4 3,986 Jun-07-2019, 07:14 AM
Last Post: DeaD_EyE
  Make bash call my own Python modules Pedroski55 10 5,037 Apr-22-2019, 04:04 PM
Last Post: snippsat
  Python bash application Ikitissimo 1 35,977 Apr-11-2018, 11:35 AM
Last Post: Gribouillis
  Command in Bash not working in python pynoob 5 4,648 Jan-05-2018, 06:28 PM
Last Post: pynoob
  How can python handle a stdout from bash shell by using Popen() ruifenghu 3 4,357 Dec-01-2017, 05:27 PM
Last Post: nilamo
  python indentation confusion hello_its_me 5 4,331 Sep-02-2017, 12:04 PM
Last Post: hello_its_me

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020