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:
The .bat delete files from a folder. I have tried running it on the gateway machine with double click and it works perfectly.
@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\*.*"
)
)
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?
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.
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?
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
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.