2

I have a script that opens a file using subprocess.Popen so I can run it in the background. I would like to be able to run this script with ./[script] [params]

#!/usr/bin/python
import subprocess
import sys
sys.path.insert(0,"./pyqt")
import gui

if __name__ == "__main__":
    subprocess.Popen(["python", "./pyqt/gui.py"])

gui.py can take parameters when being ran from a terminal by using sys.argv. Below is how I am accessing these params in gui.py

def main(*args):
    print(args)

if __name__ == "__main__":
    main(sys.argv)

How can I pass sys.argv into subprocess.Popen?

APorter1031
  • 2,107
  • 6
  • 17
  • 38

1 Answers1

5

Just forward/concatenate the arguments in the subprocess.Popen() call:

if __name__ == "__main__":
    subprocess.Popen(["python", "./pyqt/gui.py"] + sys.argv[1:])
zwer
  • 24,943
  • 3
  • 48
  • 66