3

I'm trying to capture the output of a command with the following code:

lines = subprocess.run(['ffmpeg', '-hide_banner', '-nostats', '-i', in_filename, '-vn', '-af', 'silencedetect=n={}:d={}'.format(silence_threshold, silence_duration), '-f', 'null', '-'], capture_output=True, text=True, shell=True, check=True, encoding='utf-8').stdout 
print (lines)

But lines is an empty string and nothing is printed. When capture_output=True is removed, the correct output is showed (without printing it).

I tested many combinations, including removing all the subprocess.run parameters and only include capture_output=True with the same result.

I also tested with few argument for a minimal example: subprocess.run(['ffmpeg', '-version'], capture_output=True, text=True, shell=True, check=True, encoding='utf-8').stdout

Also tested stdout=subprocess.PIPE and stderr=subprocess.PIPE as subprocess.run arguments instead of capture_output=True

I can't figure out what is happening. Thanks in advance!

Zephyr
  • 10,450
  • 29
  • 41
  • 68
Marino Linaje
  • 542
  • 5
  • 8
  • 1
    Have you tried `check_output()` from `subprocess` and `subprocess.Popen().communicate()`? Refer to [this answer](https://stackoverflow.com/a/2502883/1509809) – thuyein Jul 20 '20 at 08:39
  • According to the Python documentation I guess subprocess.run should be the prefered method. Anyway, I had always problems when using check_output() from subprocess – Marino Linaje Jul 26 '20 at 12:11

0 Answers0