0

I am attempting to run a python app within my Python script via CLI, the python app returns a few output lines that look similar to this:

Using folder: /home/pi/Downloads/
INFO:ytdl:Generating queue item for: https://youtube.com/11223344
ERROR:ytdl: Wrong URL: No video data
All done!

In my python script I run a command like this:

out = os.popen("ytdl https://youtube.com/11223344").read()

I was hoping I could capture the whole output, but it appears to only capture the following:

Using folder: /home/pi/Downloads/
All done!

Does anyone know how I can capture all the output? The end goal really is to check to see if there is any ERROR debug lines in the response... if there is then it should return a true/false value.

InvalidSyntax
  • 9,131
  • 20
  • 80
  • 127
  • 1
    Does this answer your question? [Piping popen stderr and stdout](https://stackoverflow.com/questions/10683184/piping-popen-stderr-and-stdout) – Marat Nov 08 '20 at 03:25

1 Answers1

0
in, out = os.popen4("ytdl https://youtube.com/11223344").read()

Please use peopn4 where out captures stderr in addition to stdout. You may also read about popen3 as follows to capture stderr separately from stdout

in, out, err = os.popen3("ytdl https://youtube.com/11223344").read()
Aaj Kaal
  • 1,205
  • 1
  • 9
  • 8