0

I have a test2.py file containing:

if __name__ == "__main__":
    print("Hello World")

and a test.py file with which I'm trying to run test2.py. I have tried

import os
os.system("python test2.py")

and

import subprocess
subprocess.call("python test2.py")
cmd = "python test2.py"
subprocess.run(cmd)

But none of these give me any "Hello World output". It seems that it is running the python file but without giving me any output. Would anyone know why exactly?

MVMV
  • 37
  • 6
  • 2
    Have you read [the docs](https://docs.python.org/3/library/subprocess.html)? `subprocess`, particularly about the `capture_output` parameter? – Alexander Oct 15 '21 at 00:48
  • `os.system()` doesn't return the output, it returns the exit status. You can use `os.popen()` to return the output. – Barmar Oct 15 '21 at 01:21

0 Answers0