Skip to content

Instantly share code, notes, and snippets.

@a18simongv
Created December 26, 2018 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a18simongv/bc9864a21bf6c480a888ba71fbeb43bb to your computer and use it in GitHub Desktop.
Save a18simongv/bc9864a21bf6c480a888ba71fbeb43bb to your computer and use it in GitHub Desktop.
package processBuilderCase;
import java.io.File;
public class ProcessBuilderExample {
public static void main(String[] args) {
//create the command
String cmd = "ps";
try {
ProcessBuilder pb = new ProcessBuilder(cmd);
//redirect the output to a new file named output.txt
pb.redirectOutput(new File("output.txt"));
pb.start();//execute the command
} catch(Exception ex) {
ex.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment