# Gateway Update event - execute .bat file

**URL:** <https://forum.inductiveautomation.com/t/gateway-update-event-execute-bat-file/37021>\
**Category:** Ignition\
**Created:** [July 23, 2020, 10:13pm UTC](https://forum.inductiveautomation.com/t/gateway-update-event-execute-bat-file/37021 "2020-07-23T22:13:05Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![tordvd](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tordvd/32/11525_2.png) [@tordvd](https://forum.inductiveautomation.com/u/tordvd)\
**Post date:** [July 23, 2020, 10:13pm UTC](https://forum.inductiveautomation.com/t/gateway-update-event-execute-bat-file/37021/1 "2020-07-23T22:13:05Z")

</div>

Anyone knows how to find the name of the project that is currently being saved.

I am trying to run a git autocommit script on a single project.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 23, 2020, 10:56pm UTC](https://forum.inductiveautomation.com/t/gateway-update-event-execute-bat-file/37021/2 "2020-07-23T22:56:24Z")

</div>

Not currently possible, unfortunately - although improving the project update script is on our (short) list of improvements.

---

<div class="post-metadata">

**Author:** ![tordvd](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tordvd/32/11525_2.png) [@tordvd](https://forum.inductiveautomation.com/u/tordvd)\
**Post date:** [July 24, 2020, 9:00pm UTC](https://forum.inductiveautomation.com/t/gateway-update-event-execute-bat-file/37021/3 "2020-07-24T21:00:00Z")

</div>

Im getting crazy here. My .bat works when I:

1. run the .bat file direcly from win explorer
2. from cmd (32)
3. from cmd(64) ( a bit different syntax here)

I can verify that the script runs by using a logger:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/8/08e89941504839b005a4768b7b890c72d7f6e166.png)  
And yeah, it runs twice, why?

I have stripped it down so path variables should not matter. Anyone know why github is not updating when saving project?  
`git-auto-commit.bat:`

```auto
@echo off
for /F "tokens=2" %%i in ('date /t') do set mydate=%%i
set mytime=%time%
::echo Current time is %date%:%mytime%

cd "C:\Program Files\Inductive Automation\Ignition\data\projects\myProject"
cmd /c ""C:\Program Files (x86)\Git\cmd\git.exe" add ."
cmd /c ""C:\Program Files (x86)\Git\cmd\git.exe" commit -m "Designer save @ %date%:%mytime%""
cmd /c ""C:\Program Files (x86)\Git\cmd\git.exe" push origin"

```

Update script:

```auto
logger = system.util.getLogger("SF_GW_UpdateScript")
logger.info("Running git update!")
import time
time.sleep(5)
system.util.execute(["C:\Program Files\Inductive Automation\Ignition\data\git-auto-commit.bat"])

```

---

<div class="post-metadata">

**Author:** ![cesrom](https://avatars.discourse-cdn.com/v4/letter/c/ea666f/32.png) [@cesrom](https://forum.inductiveautomation.com/u/cesrom)\
**Post date:** [July 25, 2020, 12:42am UTC](https://forum.inductiveautomation.com/t/gateway-update-event-execute-bat-file/37021/4 "2020-07-25T00:42:14Z")

</div>

One thing to consider is that in some odd cases `time.sleep` raises a `java.lang.IllegalArgumentException` as experienced by me.

So for your script it would be something like this:

```python
logger = system.util.getLogger("SF_GW_UpdateScript")
logger.info("Running git update!")
from java.lang import Thread
Thread.sleep(5000)
system.util.execute(["C:\Program Files\Inductive Automation\Ignition\data\git-auto-commit.bat"])

```

Reference:

> [@Importing time module bug](http://forum.inductiveautomation.com/t/importing-time-module-bug/33906/5):
>
> I tested the following code, and hereby I confirm that switching to java.lang.Thread solves the problem experienced with Python’s time module. import system.date from java.lang import Exception as JException, Thread def java\_sleep(): print 'Thread.sleep' print system.date.now() Thread.sleep(5000) print system.date.now() def py\_sleep(): print 'time.sleep' import time print system.date.now() time.sleep(5) print system.date.now() try: java\_sleep() p…

---

<div class="post-metadata">

**Author:** ![tordvd](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tordvd/32/11525_2.png) [@tordvd](https://forum.inductiveautomation.com/u/tordvd)\
**Post date:** [July 25, 2020, 3:36am UTC](https://forum.inductiveautomation.com/t/gateway-update-event-execute-bat-file/37021/5 "2020-07-25T03:36:13Z")

</div>

I really appreciate the input, unfortunately it did not fix my problem.

```auto
logger = system.util.getLogger("SF_GW_UpdateScript")
logger.info("Running git update!")
#import time
#time.sleep(5)
from java.lang import Thread
Thread.sleep(5000)
system.util.execute(["C:\Program Files\Inductive Automation\Ignition\data\git-auto-commit.bat"])
logger.info("Done exec git update!")

```

Yielded the same result :  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/b/0beb7a570b66eeba2293cac1ada4406fc23fa66a.png)  
But no update on git.

Anyone know how to monitor the bat file in windows logs somehow?

---

<div class="post-metadata">

**Author:** ![tordvd](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tordvd/32/11525_2.png) [@tordvd](https://forum.inductiveautomation.com/u/tordvd)\
**Post date:** [July 25, 2020, 8:45am UTC](https://forum.inductiveautomation.com/t/gateway-update-event-execute-bat-file/37021/6 "2020-07-25T08:45:47Z")

</div>

I have now included logging of the bat file (in the beginning of the file):

```auto
@echo off
set LOGFILE=batch.log
call :LOG > %LOGFILE%
exit /B
:LOG

```

The log file does not even get created when supposedly started from Ignition. When running the bat file manually, it always get created.

Tips anyone?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [July 25, 2020, 11:38am UTC](https://forum.inductiveautomation.com/t/gateway-update-event-execute-bat-file/37021/7 "2020-07-25T11:38:46Z")

</div>

Two ideas:

- Python uses backslash as the escape character. Try changing them to forward slashes in your script.

- If the batch file needs elevated privileges to run, make a shortcut with “Run as Administrator” checked, then run the shortcut from your script.

---

<div class="post-metadata">

**Author:** ![tordvd](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tordvd/32/11525_2.png) [@tordvd](https://forum.inductiveautomation.com/u/tordvd)\
**Post date:** [July 25, 2020, 9:07pm UTC](https://forum.inductiveautomation.com/t/gateway-update-event-execute-bat-file/37021/8 "2020-07-25T21:07:22Z")

</div>

Thx Jordan,  
Back slashes is actually correct.

I think I found out the main problem.

1. Ignition runs under the system account. And the system account does not have access to the SSH keys.
2. The SSH keys were created with `ssh-keygen` in git-bash, using the administrator account.

If i open a client locally, my script (see below) actually works now. Due to the client beeing launched under with the same user as the SSH key.

I have tried to copy the keys to the system account with various methods, but the battle was to mighty, and such I ran from the battlefield.

Here is a working script that can be put under gateway update event, where no .bat file is needed. But for windows the SSH key issue needs sorting out…

Im moving the gateway to linux just because of this problem! Another very annoying issue, is that `git log` display the commit as successful. I guess the logs get created before the authenitcation is checked.

```auto
logger = system.util.getLogger("GW_UpdateScript")
logger.info("Running git update!")
path="C:\Program Files\Inductive Automation\Ignition\data\projects\myProject"
import time
try:
	system.util.execute(["C:\Program Files (x86)\Git\cmd\git.exe","config","--global","user.name","'myname"])
	system.util.execute(["C:\Program Files (x86)\Git\cmd\git.exe","config","--global","user.email","myemail@fml.com"])
	system.util.execute(["C:\Program Files (x86)\Git\cmd\git.exe","-C",path,"add","."])
	time.sleep(5)
	dateStr=str(system.date.now())
	system.util.execute(["C:\Program Files (x86)\Git\cmd\git.exe","-C",path,"commit","-m","Designer save @ "+dateStr])
	time.sleep(5)
	system.util.execute(["C:\Program Files (x86)\Git\cmd\git.exe","-C",path,"push"])
	logger.info("git update done!")
except Exception as e:
	logger.infof("error, errorMsg: \n",e)

```

---

<div class="post-metadata">

**Author:** ![Nathaniel.Jarrett](https://avatars.discourse-cdn.com/v4/letter/n/f07891/32.png) [@Nathaniel.Jarrett](https://forum.inductiveautomation.com/u/Nathaniel.Jarrett)\
**Post date:** [April 19, 2022, 8:43pm UTC](https://forum.inductiveautomation.com/t/gateway-update-event-execute-bat-file/37021/9 "2022-04-19T20:43:37Z")

</div>

Thanks @tordvd ! This got us in the right direction. Just a watch out for folks looking to implement on RHEL the standard git version is 1.8 and doesn’t come with the -C option so you’ll need to upgrade to a later version. We also tested implementation with a “Message” gateway event so we could make a portal in the designer for developers to commit and add messages without committing after every single save.
