Reputation: 219
This code works fine on Computer A and doesn't work on Computer B ... I can't understand Why.. Nothing Exceptions or anything else ....On Computer A log file was created , on computer B log file was't created. Computer A and B have the same Java version... Do you have any ideas?
String str = "cmd /C dir tools>1.log";
try {
Runtime.getRuntime().exec(str);
} catch (Exception e) {
e.printStackTrace();
}
PS this code works fine on both computers
String str = "cmd /C dir tools";
Upvotes: 0
Views: 540
Reputation: 1900
You have to open the process' output stream to save the output to a file correctly.
You can do this by creating a Process object and saving that to a file:
Process p = Runtime.getRuntime().exec(str);
InputStreamReader reader = p.getInputStream();
BufferedReader buffer = new BufferedReader(reader);
String line = null;
while ((line = buffer.readLine() != null) {
//write stuff to file here
}
Upvotes: 1