I have 2 questions
1) how do I i invoke a unix shell from a java.runtime library to run a command like this
Process p = Runtime.getRuntime().exec(commands);
cat alias > bias
2) How can I read and write to a unix pipe a steady stream of data from java. Do i have to make all the system calls like open read write to a pipe
I basically want to replicate this command
cat alias > bias
where the steady stream of data will be come from java program to bias and not cat alias.
Since JDK7, there is a convinience way to do this:
ProcessBuilder pb = new ProcessBuilder("cat", "alias");
File bias = new File("bias");
pb.redirectOutput(Redirect.appendTo(bias));
pb.start();
Reference: ProcessBuilder#redirectOutput
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With