Call file .bat from scedulated script python

Goodmorning,

I need to create a script schedule, inside this script I need to call a batch file.

I try to use the python module subprocess, but the bat script was never execute.

I try to use two different code:

======FIRST======
import subprocess
subprocess.call([r’D:\Script\Call_SFTP_KOJ002.bat’], shell=True)

======SECOND======
from subprocess import Popen
p = Popen([“D:/Script/Call_SFTP_KOJ002.bat”], shell=True)
p.wait
stdout, stderr = p.communicate()
print p.returncode

I prefer the second one because I can see if the command will be execute and is possible to write the result in log file

Can somebody help me?

Thanks

Carlo

Hi, nobody reply me.

I solve the problem and share the solution:

I use this code for call file bat by python script

p = Popen(args=[“file.bat”], cwd=“D:\Script”, shell=True)
p.wait
stdout, stderr = p.communicate()
error = p.returncode
return error

Bye

1 Like

simple method

system.util.execute(["C:\\CSV\\Tools\\MoveFiles.bat"])

https://docs.inductiveautomation.com/display/DOC79/system.util.execute