System.util.execute

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.

Let’s back up a moment. From the top of the post, xion8x8 is trying to run batch file. Is there, in fact, a gui that needs to be spawned?

He hasn’t specified what the batch file is doing. It seems to be working, you just cannot see the gui.

Dear All,

Please find attached file for the test.txt (batch file is not allowed, so i upload .txt). it just print a sentence on command prompt and pause, then press any key to exit and close the command prompt.

to recap, the script is running on button actionperformed event, it able to call up command prompt, print the sentence in the batch file and pause. Press key will close the command prompt. Same script in Tag event script but command prompt is not showing up.

Thank you.
Test.txt (63 Bytes)

Commands in the batch file is working but all GUI will not be appeared but they are executed. Tested by running command to create files and copy files and etc.

Thanks for the help

2 posts were split to a new topic: System.util.execute question

Hello all,

I have been working on something like this to run a OPC-UA application which must be run as an administrator from a gateway script. There is a GUI associated with the application - but the clients would not see that since they are not logged into the server.

I am at the point where I can run this using subprocess in the script console if I am logged in on the server, but I am getting errors in my wrapper log “Cannot start service from the command line or a debugger” when I try to run the same call in the gateway script.

Some things I have tried that also only work in the client scope:
Changing the Ignition Service to login as admin account instead of local system

Using a batch file to launch the application I don’t get any error and my wrapper shows
C:\Program Files\Inductive Automation\Ignition>start C:“Program Files”\Advosol\uaPLUS.Net4.exe

My code is in tag change script which works when called from client:

path = "C:\\Users\\admin\\opc_batch_file.bat"
import subprocess as sp
sp.call([path], shell=True)

I have a ticket open for this but I want to see how others have dealt with this - Is there an IT workaround for what I am trying to do? Specifically the goal is for Ignition to call the OPC-UA application for the on the backup gateway in a redundant system when the primary fails based on the OPC-UA connected gateway tag status.

AFAIK Windows does not allow services to spawn programs with or interact with a GUI.

edit: this SO post says you can change a setting that let’s it launch but you won’t actually see it?