Subprocess & system.util.execute

Do you mean Perspective? Or do you mean the legacy WebStart technology in pre-v8 Ignition?

If Perspective, you simply cannot run any code on the local computer or work with the local computer's filesystem. Full stop.

If Vision, whether via JNLP or a local launcher, you can--client jython scripts that call system.util.execute() will run in the local client system.

In either case, a gateway script can run an external script in the gateway filesystem in the gateway environment.

3 Likes

Thanks pturmel for usual support.

Yes I mean perspective ,thanks for confirming that I can not access files in gateway PC from perspective opened in client PC .

Regards,

Perspective scripts run in the gateway, so of course can access gateway files (where the gateway service has filesystem permissions).

1 Like

Hi Pturmel,

Till now I did not solve this challenge .

At the beginning I was testing my gateway's code inside my designer script console and files opened in my designer machine and runs correctly.

I copied my py code to my gateway's machine and trying to open using same code after running it in perspective session and can not open

I have a button's click event :

system.util.sendRequest("MegaMain", "flaskStart", timeoutSec = 120)

MegaMain is my project's name ,flaskStart is my gateway's event.

inside flaskStart ,my dedicated gateway's event :

import subprocess
import os.path


# Create the command
    command = ["C:\Program Files\Git\git-bash.exe", "C:\ML\ML_MENABEV\launch.sh"]

# Use subprocess to run the command
process = subprocess.Popen(command)

I am trying now to test some simple codes inside gateway's event like :
system.util.execute(['notepad.exe', 'C:\Program Files\Inductive Automation\Ignition\Notice.txt'])

to check my gateway's response and for example ,this text file is not opened in my gateway's machine.

Ignition runs as a service and Windows does not allow services to start new processes that have user interfaces.

To be clear, system.util.execute does work when run in the context of the Ignition Gateway - you just can't expect anything with a UI to open and be visible.

4 Likes

Thanks Kevin , I found a way to run py code in the gateway , by creating new task scheduler that run the bash file in gateway machine ,and call it from perspective session as below :

   import system

# Define the name of the scheduled task
task_name = "RunBashScript"

# Define the command to run the scheduled task
command = ['cmd.exe', '/c', 'schtasks /run /tn "{}"'.format(task_name)]

# Execute the command
system.util.execute(command)