Michael
Michael

Reputation: 415

Running batch file with python script

I have a batch file, which I'm trying to run with python and it doesn't work for some reason. The batch file specifies path, then executes a certain command, like this:

Path= %systemdrive%\somefolder\secondfolder\Step1
setupEP.exe ADDLOCAL="tp"

Then python script should this file and then does some other things, which are irrelevant for the current some other similar files. The problem is batch files aren't been executed. Below is my python script

def func1():

    os.popen(r"%systemdrive%\s1.bat")
def func1():

    os.popen(r"%systemdrive%\s2.bat")

list=[func1(),func2()]

for i in list:
    t1=threading.Thread(target=i, args=(1,))
    t1.start()
    t1.join()

If I substitute the batch execution with some random loop, like

for i in range(0,60):
     print i

Everything works perfectly Help anyone?

Upvotes: 0

Views: 839

Answers (2)

Dustin Knight
Dustin Knight

Reputation: 350

You should try calling the batch file instead of opening it. Try something like

call("PathToFile/File.bat") 

Upvotes: 0

shad0w_wa1k3r
shad0w_wa1k3r

Reputation: 13372

.Thread should receive a callable object, you are passing func1() which is the result of the object after being called.

You basically need my_list = [func1, func2]

In your case, the batch files run only once on script start, not during your for loop.

Upvotes: 2

Related Questions