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?
Just forward/concatenate the arguments in the subprocess.Popen() call:
if __name__ == "__main__":
subprocess.Popen(["python", "./pyqt/gui.py"] + sys.argv[1:])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With