7

Possible Duplicate:
How do you read from stdin in python

Whats the best/easiest way to get information from a command line.

For example Im going to be running a bunch of shell scripts that return either:

200 SOLUTIONS_REVISION 
or 
400 SOLUTIONS_REVISION

after I run each script. I need to capture these "returned" strings in python as a string (to check if it passes (200) or fails (400). What would be the best way to do this (im a complete newb to python and my search seemed to mainly return getting command line arguements.

Thanks (also python 2.x preferably)

Community
  • 1
  • 1

1 Answers1

8

If you're going to run the command from your Python script then you want to look at subprocess with its stdout arguments. If you're going to run both that script and the Python script from a separate shell script then you want to pipe from one to the next and then read from sys.stdin.

Ignacio Vazquez-Abrams
  • 740,318
  • 145
  • 1,296
  • 1,325
  • well the python script will be calling the shell script (like 120 different ones). And then I'll be getting the input after each shell script (well thats the idea anyways) –  May 18 '11 at 13:11