Python Forum
How can I start a python program out of a python program?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I start a python program out of a python program?
#1
How can I start a python program out of a python program, or copy files?
Reply
#2
Quote:or copy files?
Is this your real goal?
If so, there's a better solution than running another program
Reply
#3
its just a or
I allso want to now this: "How can I start a python program out of a python program?"
Reply
#4
  • 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)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  kill python execution program lebossejames 0 234 Mar-16-2024, 11:16 AM
Last Post: lebossejames
  Unexpected termination of program when using JDBC drivers in python with jaydebeapi skarface19 2 307 Feb-17-2024, 12:01 PM
Last Post: skarface19
  Basic Coding Question: Exit Program Command? RockBlok 3 553 Nov-19-2023, 06:31 PM
Last Post: deanhystad
  how come i can't stop program Shi_Shi_Shi_Shi 4 605 Nov-16-2023, 06:20 PM
Last Post: deanhystad
  Using Autostart to run a GUI program at startup. Rpi Edward_ 1 617 Oct-28-2023, 03:19 PM
Last Post: SpongeB0B
  Program to find Mode of a list PythonBoy 6 1,065 Sep-12-2023, 09:31 AM
Last Post: PythonBoy
Question Using SQLAlchemy, prevent SQLite3 table update by multiple program instances Calab 3 743 Aug-09-2023, 05:51 PM
Last Post: Calab
  program needs this plugins robertkwild 1 471 Aug-09-2023, 04:33 PM
Last Post: deanhystad
  Help with flowchart maker program bluebouncyball 2 755 Aug-08-2023, 10:25 PM
Last Post: deanhystad
  Some help with my first python class and importing ....im making a lidar program jttolleson 7 1,198 Jul-28-2023, 08:34 AM
Last Post: jttolleson

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020