System.util.execute

I wanted to use system.util.execute to run a batch file in my computer. I am able to run the script below on a button actionPerformed event and it runs the batch file

system.util.execute([“C:\windows\system32\cmd.exe”,"/C",“start”,“C:\Users\WengFai\Desktop\Test.bat”])

When I use the exact same script in Tag Event scripts, it is not working at all and does not give any errors. I have added some codes in the Tag event scripts to make sure the event is fired (write a value to another tag). Besides that, is the “system.gui.messageBox” not working in tag event scripts too?

Anyone can help?

Thank you.

1 Like

Hello,

Tag Event scripts do not run on your computer, they run on the computer where Ignition is installed. Tag Event scripts do not run in a client, they run in the Ignition Gateway.

Your system.util.execute call in the Tag Event script will attempt to execute the bat file on the Ignition server, not on your local computer. Any errors will show up in the wrapper.log file.

A call to “system.gui.messageBox” in a Tag Event script will never work because Tag Event scripts run in the Ignition Gateway where there is no GUI.

Perhaps you could use a Client Tag Change script to do what you are trying to do.

Best,

Hi nmudge,

Thanks for the info. My computer is the Ignition Gateway. I am testing it in Designer too. Any ideas?

Check the wrapper.log file for any errors.

There are no errors in wrapper.log nor console log.

Hi!

The backslash is used to escape characters that would have a special meaning (\n for newline, for example).
So, if you need an actual backslash, you would need to use two: \.

Try using something like this:

system.util.execute(["C:\\windows\\system32\\cmd.exe","/C","start","C:\\Users\\WengFai\\Desktop\\Test.bat"])
1 Like

Hi,

Tried to use the code given, not working.

The same code is working in button actionPerformed but not working in tag event scripts.

what are the problem? out of idea

Can you post the script?

You also have to make sure the user that the gateway service runs as has permissions to the directory where you’ve put the script. The gateway doesn’t run as a regular user unless you override the service settings. Consider putting the script in a new folder under Ignition’s program folder.

1 Like

both scripts below is not working:

system.util.execute(["C:\\windows\\system32\\cmd.exe","/C","start","C:\\Users\\WengFai\\Desktop\\Test.bat"])
system.util.execute(["C:\\windows\\system32\\cmd.exe","/C","start","C:\\Program Files\\Inductive Automation\\Ignition\\batchfile\\Test.bat"])

I am running as administrator and have access on all directory. Tried to put the script in a new folder under Ignition’s program folder but not working too. Anyone tried to run batch file using tag event script?

Thank you.

I can start digging a little deeper into this, but I need one more bit of info.

Which Windwos OS are you using?

windows 7 professional 64-bit

No issues here. Runs as Tag Script, or Gateway Event Script, From my Desktop or from the root (C:). One thing that I did notice was that the cmd and Console hosts persisted, even though everything had run. I suspect that the shell never terminates, even with the “/C” switch.


I also tried using subprocess with no issues, and no persistent processes hanging on.

from subprocess import Popen, call call(['C:\\test.bat'], shell=True)

I am marking this topic as unsolved because I do not believe that it is solved. The OP emailed technical support about this issue. I have a question for Jordan on this. I have been trying to get the script to work, with limited success. I believe the OP issue has something to do with permissions and how the Ignition service is allowed to interact with the desktop. I was able to get the script to work if I allowed the service to interact with the desktop, but it was very clunky and I received a message box from the OS that I had to interact with before the script in the batch file would run. So my question is:

Jordan, did you make any changes to the OS or how the service runs?

Thanks for opening it back up, Greg.

I’ll also add what we have PM’ed over the past couple of days…

[quote=“xion8x8”]Subject: system.util.execute

[quote=“JordanCClark”]No issues here. Runs as Tag Script, or Gateway Event Script, From my Desktop or from the root (C:). One thing that I did notice was that the cmd and Console hosts persisted, even though everything had run. I suspect that the shell never terminates, even with the “/C” switch.
[attachment=0]2015-06-23_6-56-06.png[/attachment]

I also tried using subprocess with no issues, and no persistent processes hanging on.

from subprocess import Popen, call call(['C:\\test.bat'], shell=True)[/quote]

Hi Jordan,

The code given is not running for my computer, it hangs the whole Ignition designer forever. any idea?

I have accidentally locked my topic by clicking the “solved” button but actually it is not solved yet.

Thank you.[/quote]

Sorry for the late reply.

Hmm. Let’s do a little housekeeping…

This will (hopefully) give you a fresh start. The only thing is that any shortcuts created by Ignition will likely get deleted.

remove any cached webstart apps:
javaws.exe -uninstall

Delete ignition user folder:
C:\Users{userName}.ignition

When you restart the designer a fresh copy of the jython libraries will get downloaded. Perhaps that may do the trick.

Nope. Granted, I am an administrator, but no permissions were changed for Ignition.

If I recall correctly, with UAC enabled, services running with ‘interact with the desktop’ are actually interacting with a virtual gui that corresponds to an remote desktop “/console” or “/admin” connection. Microsoft has been trying to kill off gui-visible services for ages …
My Windows7 VM is use for Rockwell Software has UAC turned off so RSLinx Classic can interact with the desktop. That’s became a requirement for RSLinx Classic when Vista came out.

I have followed the steps from Jordan but no luck and it is not working to me. Do i need JDK or JRE will do?

UAC had been disabled in my computer.

I only use JRE.

My thought is that this is a permissions issue. I was able to execute a batch file from a tag event script if I allowed the Ignition service to interact with the desktop. However, I was prompted to view a message before it would run in its own window. It would not be very desirable to run it in this way. I have admin permission on my workstation, but that doesn’t mean that IT hasn’t put something in place to prevent services from executing something.

Ok, some more to add on this. I don’t think there is going to be anything on the Ignition side of things that can be done. As of right now I am not able to find a solution to this. I am going to speak with my IT department and see if there is anything they can add. What I am seeing is this. The script runs the batch file from the tag event script. However, it starts a new process that I can see in Task Manager, but it runs the process in the background. So its running, just no GUI. This would be some sort of an issue with the OS or permissions. I will get back to you once I have more.