Showing posts with label exec. Show all posts
Showing posts with label exec. Show all posts

Monday, January 30, 2012

ProcessBuilder Runtime Redirecting Output and Exec uting

The following discuss details of the problem:


ProcessBuilder redirecting output


http://stackoverflow.com/questions/5986324/processbuilder-redirecting-output

Shell redirection operators are unknown to ProcessBuilder. Put your command in a shell script and execute it, as shown here. Alternatively, use bash -c, as shown here.



Or prepending "bash -c" to the exec


http://stackoverflow.com/questions/5740390/printing-my-macs-serial-number-in-java-using-unix-commands/5740673#5740673


How to use OutputStream for output redirection


http://stackoverflow.com/questions/3777654/problem-with-runtime


Split a string containing command-line parameters into a String[] in Java


http://stackoverflow.com/questions/3259143/split-a-string-containing-command-line-parameters-into-a-string-in-java
Wonderful answer here:


Here is a pretty easy alternative for splitting a text line from a file into an argument vector so that you can feed it into your options parser:
This is the solution:
public static void main(String[] args) {
    String myArgs = Commandline.translateCommandline("-a hello -b world -c \"Hello world\"");
    for (String arg:myArgs)
        System.out.println(arg);
}