简体   繁体   中英

Python run separate scripts from my script

I have 2 scripts, and I need to run one script from another, get its output, and assign it into variable inside the first script, and use it.

The second script need to give me some output of a text within 5-7 characters.

I tried to run this in my first script, but it didn't work.

import subprocess

capnum = subprocess.run(["../python3 test-ver2.py"])
print("Result: " % capnum.returncode)

I believe subprocess.getoutput() is what you're looking for:

import subprocess

capnum = subprocess.getoutput("..\\python3 test-ver2.py")
print(f"Result: {capnum}")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM