Python Forum
How can I start a python program out of a python program? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How can I start a python program out of a python program? (/thread-13759.html)



How can I start a python program out of a python program? - peer - Oct-30-2018

How can I start a python program out of a python program, or copy files?


RE: How can I start a python program out of a python program? - Larz60+ - Oct-30-2018

Quote:or copy files?
Is this your real goal?
If so, there's a better solution than running another program


RE: How can I start a python program out of a python program? - peer - Oct-30-2018

its just a or
I allso want to now this: "How can I start a python program out of a python program?"


RE: How can I start a python program out of a python program? - Larz60+ - Oct-30-2018

  • You can import it. And then just run what you need from the imported module
    import mymodule
    
    mymodule.myfunction()
  • That being said, there are other ways, one (which is unsafe) is to use exec:
    execfile('mymodule.py')
  • You can spawn it using os (again not recommended):
    import os
    
    os.system('python mymodule.py')
  • And finally, save the best for last, use subprocess
    import subprocess
    runproc = subprocess.run([python mymodule.py])
    
    
    # if you need to capture output of mymodule use:
    runproc = subprocess.run([python mymodule.py]
        stdout=subprocess.PIPE,
    )
    
    results = runproc()
    print(results)