0

This program starts the first program. But I also want to run the second parallel. How can i start two or more programs with a script?

# start many programs execfile('C:/Dokumente und Einstellungen/schnei17/Desktop/python/zeit/1.py') print 1 execfile('C:/Dokumente und Einstellungen/schnei17/Desktop/python/zeit/2.py') print 2 
2
  • 5
    Why aren't you using subprocess for this? Commented May 10, 2011 at 14:11
  • 1
    subprocess makes this much easier unless you need to share data between the processes in which case you would use multiprocessing Commented May 10, 2011 at 14:14

2 Answers 2

4

try with the subprocess python module :

import subprocess subprocess.Popen(["python.exe", 'C:/Dokumente und Einstellungen/schnei17/Desktop/python/zeit/1.py']) subprocess.Popen(["python.exe", 'C:/Dokumente und Einstellungen/schnei17/Desktop/python/zeit/2.py']) 

It will launch the 2 scripts in parallel (if your python.exe is in PATH).

Sign up to request clarification or add additional context in comments.

2 Comments

I get an error: WindowsError: [Error 193] (it is not a win-32 application)
I updated with the python.exe call before script name, you can replace python.exe by the full path to your python executable
0

To start several applications I'd recommend to use threading.

shellcommands=("notepad.exe", "calc.exe", "mspaint.exe") import os import sys import time import datetime import threading import subprocess class ThreadClass(threading.Thread): # Override Thread's __init__ method to accept the parameters needed: def __init__ ( self, command ): self.command = command threading.Thread.__init__ ( self ) def run(self): now = datetime.datetime.now() print "%s %s %s \n" % (self.getName(), self.command,now) try: subprocess.call(self.command, shell=True) except Exception, err: print "ERROR: %s\n" % str(err) for cmd in shellcommands: t = ThreadClass(cmd) t.start() sys.exit() 

1 Comment

That will leave python running too, and block on the console. Unless this is intended, it's better to use subprocess.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.