Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 575
sashoalm Avatar asked Sep 07 '18 09:09

sashoalm


1 Answers

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.

like image 132
sashoalm Avatar answered Oct 22 '22 07:10

sashoalm