I have a method like the following:
public void launch(String cmd, String [] args, String workingDir)
Inside this method I call ProcessBuilder.
How can I call ProcessBuilder including an arbitrary number of args included in my args parameter?
E.g., something like this:
ProcessBuilder pb = new ProcessBuilder(cmd, args);
I notice ProcessBuilder does have this contructor:
ProcessBuilder(List<String> command)
Maybe I could use that somehow.
ProcessBuilder has a varargs Constructor –
ProcessBuilder(String... command)– so you can use that, but you’ll need to make your command and arguments into a single array.Otherwise you can use the other Constructor as follows: