ch.vorburger.exec icon indicating copy to clipboard operation
ch.vorburger.exec copied to clipboard

Parse full existing command line

Open vorburger opened this issue 5 years ago • 0 comments
trafficstars

When using this library somewhere where there already is a "command line" (as in an executable + arguments), then the ManagedProcessBuilder as-is currently is more in the way than helpful, as you have to write code to split it:

        var execName = cmdLine.substring(0, cmdLine.indexOf(' ')).strip();
        var procBuilder = new ManagedProcessBuilder(execName);
        var execArgs = cmdLine.substring(execName.length());
        for (String arg : Splitter.on(' ').trimResults().omitEmptyStrings().split(execArgs)) {
            procBuilder.addArgument(arg);
        }

For such uses cases, it would be handy if the ManagedProcessBuilder had a static factory method such as fromCommandLine(String commandLine) which did something like above. It should take quotes appropriately into account, like a shell.

This would be the ManagedProcessBuilder time equivalent of the already existing ch.vorburger.exec.ManagedProcess.getProcLongName() method (which could be renamed to getCommandLine() at this occassion; and a toString() could be added which uses getCommandLine(), getWorkingDirectory() (as getProcLongName() does) and other state information.

vorburger avatar Nov 15 '20 19:11 vorburger