Launching a Detached Process

Current Version: v8.3.1
Last Version Used in Production: v7.9.21
Visualization Module: Vision

scenario: vision client launches a set of http API drivers on the host machine so it can communicate with various equipment installed on the machine. this strategy cannot be changed at this time due to time constraints. starting of processes from vision clients is no longer working the way it used to in v7.9.21, breaking this setup.

v7.9.21 of Ignition allowed vision clients to launch completely detached processes which would not close when the vision client closed and would work pretty much as if they had been launched by the user. Using the python subprocess module worked without issue.

v8.3.1 seems to have changed something because now processes are being launched as child processes, which close when the vision client closes. After reworking to use java libraries, the processes can be made to start detached, but they still hang or crash for some reason (tested with multiple apps).

import os
from java.lang import ProcessBuilder
from java.io import File

# inputs
filepath = "<path/to/executable>"
minimized = False


fn = os.path.basename(filepath)
dp = os.path.dirname(filepath)
cmds = [
	"cmd.exe",
	"/c",
	"start",
	"/B",
]
if minimized:
	cmds.append("/MIN")
cmds.append(fn)
pb = ProcessBuilder(cmds)
pb.directory(File(dp))
pb.redirectOutput(File(os.devnull))
pb.redirectError(File(os.devnull))
pb.redirectInput(File(os.devnull))
process = pb.start()

Does anyone know how to fix this / a workaround?

I couldn't tell you for sure what changed - nothing intentionally in Ignition. It's possible that the various Java upgrades internally caused this incidentally.

As for a workaround, I would have suggested exactly what you're already doing - asking the OS to launch (with its native tools) a separate process 'detached'.

Any events in Windows' Event Viewer? What if you run something guaranteed to run forever, like a batch file that just loops indefinitely? What if you write the stdout and stderr of the detached process out to a file?

Any security software on your machine that might be seeing a random executable getting launched by cmd.exe in the background and assuming it's malicious?

1 Like

@paul-griffith, thanks for getting back to me.

After some more investigation, it looks like something is wrong with the specific Windows machine I was testing on. Seems to be some USB power delivery thing, causing the drivers to hang indefinitely. Testing the same apps on other machines, they do not hang.

The issue described with launched subprocesses now becoming child processes is real though. If anyone else is trying to launch detached processes, they may need to explore workarounds like the code in my initial post.

UPDATE: Further testing revealed I was wrong and all computers show the same results, but the executable launched seems to maybe fail in different ways depending on the machine. After A LOT of trial and error trying to find a way to launch apps normally from a vision client I have concluded it is no longer possible. Every conceivable workaround seems to be blocked by the increased security in v8.* (I am coming from v7.9.21). I plan on refactoring the system so apps don't need to launch from the Ignition vision app, but I am under deadline so in the meantime I am going to make a separate python HTTP web service which will handle launching these apps upon request (part of the problem is some of the software being launched is a bit janky and needs to be restarted in certain contexts).

It might be good, if not already done somewhere, to mention this cannot really be done anymore. The script I posted does seem to work on the gateway and from the designer, at least for the simple CLI I tested with in those cases, but attempting to launch more complex apps (background or GUI) from a vision client fails in all kinds of weird ways.

2 Likes