Storing the Output of a Child Process in a File
Wouldn't it be useful to store the data in a file? This is one of the reasons why you may be interested in having a process to run a program (or a series of programs) – capturing their output in a log file to study them. By adding a small modification to the process launcher, you could capture whatever it is that is sent to System.out
by the other program. This is really powerful as you could make a program that could be used to launch any existing command in your operating system and capture all of its output, which could be used later to conduct some sort of forensic analysis of the outcomes:
Example07.java
26Â Â Â Â Â Â Â Â Â // write to the child's System.in 27Â Â Â Â Â Â Â Â Â OutputStream out = process.getOutputStream(); 28Â Â Â Â Â Â Â Â Â Writer writer = new OutputStreamWriter(out); 29Â Â ...