Help making system.util.execute work on Windows

Hello,

I am trying to implement automatic git push on project update. Everything looks fine except for the system.util.execute function which does not seem to be working for me.

I have a Windows Server 2022, and Ignition 8.1.41 is running as a service behind a non-admin Windows Service Account with batch job rights, and interactive logon disabled.

I have readen a couple of posts but no found no real solution. Permission problems does not make sense to me because, if so, Ignition would not run either. Even a minimal .bat file that simply writes a .txt file in the same Ignition install directory does not work.

This is the minimal .bat file:

echo "it works" > "C:\Program Files\Inductive Automation\log.txt"

This is the script:

system.util.execute(['%ProgramFiles%/Inductive Automation/Ignition/data/git-auto-commit.bat'])

I tried also giving local admin permissions to the service account, with no success.

Thanks!!

Simply not true. Ignition only needs local privileges to run, and that is all it gets when running as the default LOCAL SYSTEM user.

The service also has no connection to what you do on the desktop as far as networks are concerned, so your testing in the terminal is insufficient.

Instead of using system.util.execute(), which is
fire-and-forget, use java's ProcessBuilder so you can collect the output and error streams from your batch file's execution.

1 Like

For Diamond and anyone else having problems with system.util.execute for launching a windows batch file, there are essentially 2 main hurdles: Getting the syntax correct in the Ignition command, and then debugging the batch file execution. Suggestions:

  1. Follow the syntax shown in the Users Manual for the command and arguments using double backslashes. Specifically, it should look like this for example:

       system.util.execute(['C:\\mydir\\mysubdir\\mybatch.bat', 'myarg'])
    

I have never tried using a path variable such as %ProgramFiles% in this command. While it may be possible, I would suggest starting with a hard path first, and to a directory path that I created (i.e. avoid the %ProgramFiles% directory as it is created by Windows) thus eliminating the potential permissions issue.

  1. Execution of this command happens in the background so there is no visual way to know it worked and by default, no log files to check. In this instance, diamond redirected the stdout to a pseudo log file (~works" > "C:Prog~). While on the right track, this only provides a log entry if everything worked. A more verbose approach is to redirect both stdout as well as stderr to the log file. There are many ways of doing this but in it's simplest form one can do this:

echo "it works" >> "C:\Program Files\Inductive Automation\log.txt" 2>&1

Once the file "log.txt" is created, using ">>" for the redirect causes windows to append info to the log rather than overwrite it. I find this to be more useful during debug. Also, adding "2>&1" to the end of the redirect causes both stderr and stdout to go to log.txt. Easy to do an internet search for other syntax for this concept.

Thank you @Robert_Post,

I finally did manage to solve this issue recently. I succeded by using Powershell (.ps1) instead of .bat files. Also, exporting logs to .txt files resulted being the way to go instead of the ProcessBuilder approach, which only caused gateway malfuntion in my case. I also did use the verbose approach (thanks ChatGPT).

For me, the root problem was that git was rejecting to push changes because the account behind Ignition execution did not match the account which initialized the repository.