0

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\Step1setupEP.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 perfectlyHelp anyone?

askedApr 20, 2017 at 13:17
Michael's user avatar
1
  • 2
    Don't overwritePATH. Update it insteadset "PATH=%systemdrive%\somefolder\secondfolder\Step1;%PATH%"CommentedApr 20, 2017 at 13:21

2 Answers2

2

.Thread should receive a callable object, you are passingfunc1() which is the result of the objectafter being called.

You basically needmy_list = [func1, func2]

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

answeredApr 20, 2017 at 13:20
shad0w_wa1k3r's user avatar
Sign up to request clarification or add additional context in comments.

3 Comments

1. How do you explain then, that my script runs counting to 60? 2. That doesn't explain why batch files aren't been executed. They should have been executed at least one time
They aren't being executed because you call them only once. Yourfor loop does run 60 times. Pass them a callable! Passfunc notfunc().
Accepted. Thanks.
0

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

call("PathToFile/File.bat")
answeredApr 20, 2017 at 13:28
Dustin Knight's user avatar

Comments

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.