2

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!

3
  • If you read the docs, at the very end of a function description there are changes described depending on Python version. In this case the parameter was added in Python 3.7. Commented Mar 28, 2020 at 14:56
  • 1
    You need to put the args in a list like: ['python3', 'try1.py']. Commented Mar 28, 2020 at 14:57
  • What's new in python 3.7 Subprocess Commented Mar 28, 2020 at 14:59

1 Answer 1

4

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'])
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.