Trying to Execute a .bat file using System.util.execute()

Any one have any idea why the System.util.execute() is not working during perspective session but in script consol it is working.

Basically i am trying to run a bat file from the ignition using System.util.execute() function .

system.util.execute(['D:\Reports\file.bat'])

I'm pretty sure that Perspective does not have access to the file system. If you want your gateway to run the file, initiated from a Perspective client, you have some options.
You could have the client alter a tag and react to that with a tag change event. I think a message listener would also work.

I think you need to escape your backslashes.
system.util.execute(['D:\\Reports\\file.bat'])

See this post from earlier this week:

1 Like

Perspective scripts run in the gateway, not on the machine that is running the client. Script console runs in the Designer with functionality similar to a Vision client, which does have access to run things locally. If you need to run arbitrary code in the client machine, you need Vision, not Perspective.

3 Likes

well unless you create an uri scheme and install it on the clients pc

That isn't running arbitrary code. That's opening an app with a parameter.

Which is no less effort than installing a Vision client launcher on the machine. Without having to develop the URI handler yourself. (And the gateway provides the vision launcher right there on the home page.)

3 Likes

You could use it to open the cmd and run the bat file.
But yes it does require an install. if he already is halfway making his project in perspective, then it might be easier to make an uri than to convert back to vision.
And if this batfile is only located and needed on a few specific clients, it 's not to much work to install them

Maybe. But then the end-user will want status from the external application....

You could include an api call in the batfile if you need a response, but yes than it is getting quite a bit more complicated.

he maybe just forgot to put the batfile in the gateway xd
Its a new user on the forum so we'll need more context from him to get a good solution, i was just saying its possible if its really needed ^^