4

I am trying to create a new process to run another python file using the following code.

proc = subprocess.Popen(["python test.py"],shell=True)#,stdout=DEVNULL, stderr=STDOUT
proc.wait()

It works on window but when I tried in an ubuntu console. It would trigger the python console/interpreter instead of running the python file. Any help would be appreciated

1
  • I would strongly suggest you to create a minimal, reproducible example (stackoverflow.com/help/minimal-reproducible-example) to demonstrate your problem. Commented Sep 10, 2019 at 3:48

2 Answers 2

1

As i commented the previews answer, do not use shell=True if you don't need it, please refer to python doc, there are serious security implication using this option.

working example:

╭─root@debi /tmp
╰─# cat 1.py
def main():
  print("ok")

if __name__ == '__main__':
    main()
╭─root@debi /tmp
╰─# cat 2.py
import subprocess

def main():
    proc = subprocess.Popen(["python", "1.py"])
    proc.wait()

if __name__ == '__main__':
    main()
╭─root@debi /tmp
╰─# python3 2.py
ok
╭─root@debi /tmp
╰─#
Sign up to request clarification or add additional context in comments.

Comments

0

You have to separate arguments python and test.py for the things to work properly:

proc = subprocess.Popen(["python", "test.py"],shell=True)
proc.wait()

1 Comment

what is the point of shell=True are you aware of this ? docs.python.org/2/library/… at least mention the security implication!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.