# System.util.execute() does not work when executing .bat

**URL:** <https://forum.inductiveautomation.com/t/system-util-execute-does-not-work-when-executing-bat/79074>\
**Category:** Ignition\
**Created:** [September 13, 2023, 12:55pm UTC](https://forum.inductiveautomation.com/t/system-util-execute-does-not-work-when-executing-bat/79074 "2023-09-13T12:55:46Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Castro](https://avatars.discourse-cdn.com/v4/letter/d/ce73a5/32.png) [@David\_Castro](https://forum.inductiveautomation.com/u/David_Castro)\
**Post date:** [September 13, 2023, 12:55pm UTC](https://forum.inductiveautomation.com/t/system-util-execute-does-not-work-when-executing-bat/79074/1 "2023-09-13T12:55:46Z")

</div>

Hello everyone.  
I'm trying to execute a .bat file on my gateway, but it's not working. I've tried many different ways of writing it and different paths, I've done a lot of research on the forum, and I've also tried creating a shortcut with the "Run as administrator" option checked, but without success.  
Could you help me?  
Here are some of the commands I've tried:

```auto
system.util.execute(['cmd.exe', '/C', 'C:/Program Files/Inductive Automation/Ignition/batfile/Shortcut'])

system.util.execute(["cmd.exe", "/C", "C:\Program Files\Inductive Automation\Ignition\batfile\Shortcut"])

system.util.execute(["C:\\windows\\system32\\cmd.exe","/C","start","C:\\Program Files\\Inductive Automation\\Ignition\\batfile\\Shortcut"])

system.util.execute(["C:\\windows\\system32\\cmd.exe","/C","start","C:\\Program Files\\Inductive Automation\\Ignition\\batfile\\Clean.bat"])

system.util.execute(['C:\\windows\\system32\\cmd.exe','/C','start','C:\\Program Files\\Inductive Automation\\Ignition\\batfile\\Clean.bat'])

system.util.execute(['C:\\windows\\system32\\cmd.exe','/C','start','C:\\Program Files\\Inductive Automation\\Ignition\\batfile\\Shortcut'])

```

I also tried it in the C:/ directory and on the desktop

Thanks in advance, Best regards.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [September 13, 2023, 12:57pm UTC](https://forum.inductiveautomation.com/t/system-util-execute-does-not-work-when-executing-bat/79074/2 "2023-09-13T12:57:01Z")

</div>

Where are you executing/testing this script from?

---

<div class="post-metadata">

**Author:** ![David\_Castro](https://avatars.discourse-cdn.com/v4/letter/d/ce73a5/32.png) [@David\_Castro](https://forum.inductiveautomation.com/u/David_Castro)\
**Post date:** [September 13, 2023, 12:59pm UTC](https://forum.inductiveautomation.com/t/system-util-execute-does-not-work-when-executing-bat/79074/3 "2023-09-13T12:59:02Z")

</div>

In Gateway Events Scripts, tag Change and have it linked to a button.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [September 13, 2023, 12:59pm UTC](https://forum.inductiveautomation.com/t/system-util-execute-does-not-work-when-executing-bat/79074/4 "2023-09-13T12:59:42Z")

</div>

What are you expecting to happen when the batch script executes? How have you determined it is or isn't running?

---

<div class="post-metadata">

**Author:** ![David\_Castro](https://avatars.discourse-cdn.com/v4/letter/d/ce73a5/32.png) [@David\_Castro](https://forum.inductiveautomation.com/u/David_Castro)\
**Post date:** [September 13, 2023, 1:03pm UTC](https://forum.inductiveautomation.com/t/system-util-execute-does-not-work-when-executing-bat/79074/5 "2023-09-13T13:03:15Z")

</div>

The .bat delete files from a folder. I have tried running it on the gateway machine with double click and it works perfectly.

```auto
@echo off
set carpeta_base=C:\ProgramData\MySQL\MySQL Server 8.0\Uploads
set carpetas=Folder1 Folder2 Folder3

cd /d %carpeta_base%

for %%f in (%carpetas%) do (
    if not exist "%%f" (
        mkdir "%%f"
    ) else (
        del /q "%%f\*.*"
    )
)

```

---

<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:** [September 13, 2023, 1:10pm UTC](https://forum.inductiveautomation.com/t/system-util-execute-does-not-work-when-executing-bat/79074/6 "2023-09-13T13:10:00Z")

</div>

I run a batch file like so with system.util.execute - `system.util.execute(['C:\\BackupFiles\\DeleteBackup.bat'])` I just call the batch directly, no preceding arguments required. This one runs on my GW as well and does similar to yours, deletes old files. What if you try it this way?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 13, 2023, 1:11pm UTC](https://forum.inductiveautomation.com/t/system-util-execute-does-not-work-when-executing-bat/79074/7 "2023-09-13T13:11:11Z")

</div>

Consider using Java's `ProcessBuilder` instead of `system.util.execute` so that you can capture and log the output of the script. Also consider that the gateway doesn't run as a normal user by default and may not have privileges in the target folders. That you can run the batch file yourself on the gateway means nothing.

---

<div class="post-metadata">

**Author:** ![David\_Castro](https://avatars.discourse-cdn.com/v4/letter/d/ce73a5/32.png) [@David\_Castro](https://forum.inductiveautomation.com/u/David_Castro)\
**Post date:** [September 13, 2023, 1:50pm UTC](https://forum.inductiveautomation.com/t/system-util-execute-does-not-work-when-executing-bat/79074/8 "2023-09-13T13:50:58Z")

</div>

I tried it again and it didn't work.

---

<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:** [September 13, 2023, 1:58pm UTC](https://forum.inductiveautomation.com/t/system-util-execute-does-not-work-when-executing-bat/79074/9 "2023-09-13T13:58:43Z")

</div>

Ok, try what Phil said regarding using JavaProcessBuilder so you can get some output from the attempt as well as checking the permissions. What user is your Ignition service running as - do they have the permissions to run this file?

---

<div class="post-metadata">

**Author:** ![David\_Castro](https://avatars.discourse-cdn.com/v4/letter/d/ce73a5/32.png) [@David\_Castro](https://forum.inductiveautomation.com/u/David_Castro)\
**Post date:** [September 13, 2023, 2:43pm UTC](https://forum.inductiveautomation.com/t/system-util-execute-does-not-work-when-executing-bat/79074/10 "2023-09-13T14:43:56Z")

</div>

As you can see, it appears to have executed successfully, but it still doesn't work. The .bat file is executable by SYSTEM, just like the folders that are being deleted

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/0/f093b40bae573d6f7bb6590687f158faf2abeae4.png)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/3/731172743d9b491d5eb530c1a520ecf227ea8eb0.png)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 13, 2023, 2:59pm UTC](https://forum.inductiveautomation.com/t/system-util-execute-does-not-work-when-executing-bat/79074/11 "2023-09-13T14:59:28Z")

</div>

> [@David\_Castro](#):
>
> it appears to have executed successfully

~~`system.util.execute` is "fire-and-forget". It doesn't wait for or check on what it launches. Its own success means nothing. That's why you should be using `ProcessBuilder`.~~

What showed up in your log?

Also, you'll need to capture the error stream, too.
