TypeError while using subprocess

Viewed 282

I am using subprocess to capture output of another python file into the current one.Here is my code-

    import subprocess
    a= subprocess.run('python3 try1.py', capture_output=True,shell=True)

But when I run the code, I get an error-

<pre>Traceback (most recent call last):
  File &quot;test2.py&quot;, line 4, in &lt;module&gt;
    c1= subprocess.run(&apos;python3 test2.py&apos;, capture_output=True,shell=True)
  File &quot;/usr/lib/python3.6/subprocess.py&quot;, line 423, in run
    with Popen(*popenargs, **kwargs) as process:
TypeError: __init__() got an unexpected keyword argument &apos;capture_output&apos;
</pre>

I am running Python 3.6.8. Also, a file named subprocess.py doesn't exist on my PC. It used to, but I deleted it. Thanks for all help!

1 Answers

The capture_output parameter does not exist in Python 3.6 which is what you are using. Hence the error. You can use this instead:

subprocess.check_output(['python3', 'try1.py'])
Related