How to use "executeCommandLine" correctly

You can not use redirection, pipeing with starting multiple programs in executeCommandLine.
You can start only 1 program with its parameters.
Perhaps the function name executeCommandLine is misleading, it should be executeProgram or executeProcess.

If you want redirection and pipeing with starting multiple programs you have to use a script as you tried or use bash with the command line as direct parameter:

var pingresult = executeCommandLine(Duration.ofSeconds(5), "/bin/bash", "-c", "/bin/ping -c5 -W1 192.168.178.99 > /dev/null && /bin/echo 'online' || /bin/echo 'offline'")
3 Likes