System.util.execute not working

I can’t get system.util.execute to do anything. When I run system.util.execute([‘notepad.exe’, ‘c:\program files\inductive automation\ignition\license.txt’]) like the example I don’t get any errors but nothing happens. I made sure that the “Allow service to interact with desktop” option was checked. I also made sure that the file existed using system.file.fileExists() and it returned true. What am I doing wrong?

Because Ignition runs as a service I don't think it's possible for code running in gateway scope (tags, perspective) to open a GUI window even with "interact with desktop" enabled.

1 Like

this might be redundant but would it be possible to run a .py file from the execute command (its python 3.6) if it isn’t opening anything

My experience outside of Ignition with running .py files from within a service is that they run fine, you just, as stated, won’t see anything on the display.

The other issue here, of course, is that notepad would open (if this indeed did work) on the gateway server, not the client, since all scripts in Perspective run on the Gateway.

5 Likes

Hello, I am new to this but has anyone resolved this issue. I have ignition edge and am using perspective. I need to run an external .bat file which is on the windows/desktop but i can't seem to get it to work. If i use the script console it works but not if i use with a button ?

Any Help really welcome

All scripting in a Perspective session executes on the gateway. Unless you happen to be running your browser on the same server as the gateway is installed there is no possibility of executing anything on the user desktop (or anywhere else) from a browser.

Thanks Kevin. I think I know what you mean

I have a system where the browser and the gateway are installed on the same machine, and I am trying to open an application, such as notepad.exe. Per your verbiage, is this then possible?

I appreciate any help or advice on this.

Generally, no. Windows doesn't allow background services (Ignition Gateway) to interact or spawn programs with a UI.

If you want to spawn a program with a GUI then doing it from a Vision application is probably the easiest way.

3 Likes

Is it possible to open an external python script from the gateway machine? I can do it in the script console in ignition designer with no issue with the system.util.execute(), but I have not been able to make it from a tag script or gateway event.

In this article shows ways to accomplish the calling from ignition to python, but I do not know how I can achieve this from the Gateway machine.

Any help is appreciated.

You cannot.

If you are trying to open an external executable where the Perspective client is, you run into two problems:

  1. The jython in your action is running in the gateway, not in the browser's environment, and
  2. Browsers don't let websites run arbitrary local executables. That would be a huge security hole. It is possible to install a URL handler in a browser to open an application, but that can only happen as part of a local software install outside the browser.

If you are trying to open a GUI executable on the gateway itself, you will be blocked by Windows' isolation between desktops and background services. (Similar in Linux.)

If you are trying to run a non-GUI script on the gateway, system.util.execute() should work if the gateway service has permissions for all of the files and folders you are attempting to access, and you don't expect to see anything open. If you need to get results from and external program, use java's ProcessBuilder to set up monitoring of pipes and exit code.

2 Likes

You can get around this by setting the Ignition service to run under a user that does have privileges to do the things you're trying to do, instead of under the default SYSTEM user

Hmmm, pretty sure the "Interact with Desktop" stuff became a lie in Windows 8 or 10. You should try it and let us know.

Oh right, yes I think you're right. I was thinking about accessing fileshare paths and other security permissions. But actually executing things is still not allowed, as you mentioned. That's what I get for trying to process things in the wee hours

1 Like