7

My Python script will run a bunch of shell scripts that output either 200 SOLUTIONS_REVISION or 400 SOLUTIONS_REVISION when run. The 200 in the output indicates success and the 400 indicates failure.

How can I capture these "returned" strings as strs in the Python code, for further processing?

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
  • 1
    http://stackoverflow.com/questions/1450393/how-do-you-read-from-stdin-in-python – o0'. May 18 '11 at 13:05
  • This question was originally closed as a duplicate of one about reading from the standard input. OP described the question as being about reading from the command line, which would be another duplicate. However, **both are wrong**. The question - as determined by the answerer - is **actually** about reading **from the standard output of a subprocess**. Which... is yet another duplicate. – Karl Knechtel Feb 05 '23 at 09:58

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
  • 776,304
  • 153
  • 1,341
  • 1,358
  • 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