# Call file .bat from scedulated script python

**URL:** <https://forum.inductiveautomation.com/t/call-file-bat-from-scedulated-script-python/30163>\
**Category:** Ignition\
**Tags:** python\
**Created:** [November 21, 2019, 9:54pm UTC](https://forum.inductiveautomation.com/t/call-file-bat-from-scedulated-script-python/30163 "2019-11-21T21:54:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![carlo.lodirizzini](https://avatars.discourse-cdn.com/v4/letter/c/a3d4f5/32.png) [@carlo.lodirizzini](https://forum.inductiveautomation.com/u/carlo.lodirizzini)\
**Post date:** [November 21, 2019, 9:54pm UTC](https://forum.inductiveautomation.com/t/call-file-bat-from-scedulated-script-python/30163/1 "2019-11-21T21:54:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![carlo.lodirizzini](https://avatars.discourse-cdn.com/v4/letter/c/a3d4f5/32.png) [@carlo.lodirizzini](https://forum.inductiveautomation.com/u/carlo.lodirizzini)\
**Post date:** [February 5, 2020, 8:23am UTC](https://forum.inductiveautomation.com/t/call-file-bat-from-scedulated-script-python/30163/2 "2020-02-05T08:23:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![diat150](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diat150](https://forum.inductiveautomation.com/u/diat150)\
**Post date:** [February 6, 2020, 3:14am UTC](https://forum.inductiveautomation.com/t/call-file-bat-from-scedulated-script-python/30163/3 "2020-02-06T03:14:40Z")

</div>

simple method

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

```

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [February 6, 2020, 1:01pm UTC](https://forum.inductiveautomation.com/t/call-file-bat-from-scedulated-script-python/30163/4 "2020-02-06T13:01:01Z")

</div>

[https://docs.inductiveautomation.com/display/DOC79/system.util.execute](https://docs.inductiveautomation.com/display/DOC79/system.util.execute)
