sashoalm
sashoalm

Reputation: 79467

subprocess.run() doesn't return stdout or stderr

I tried using subprocess.run as described in this answer, but it doesn't return anything for stdout or stderr:

>>> result = subprocess.run('echo foo', shell=True, check=True)
>>> print(result.stdout);
None
>>> print(result.stderr);
None

I also tried using capture_output=True but I got an exception __init__() got an unexpected keyword argument 'capture_output', even though it is described in the documentation.

Upvotes: 13

Views: 8130

Answers (1)

sashoalm
sashoalm

Reputation: 79467

I had made a mistake, I hadn't added stdout=subprocess.PIPE:

result = subprocess.run('echo foo', shell=True, check=True, stdout=subprocess.PIPE);

Now it's working.

Upvotes: 14

Related Questions