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.

2 Likes