I am running a command line command from java:
ping localhost > output.txt
The command is send via a Java like this:
Process pr = rt.exec(command);
For some reason the file is not created, but when i run this command from the
command line itself, the file does create and the output is in that file.
Why doesn’t the java command create the file?
Because you haven’t directed it to a file.
On the command line, you’ve requested that it be redirected to a file. You have to do the same thing in Java, via the InputStream provided by the Process object (which corresponds to the output stream of the actual process).
Here’s how you get the output from the process.
You can read from this until EOF, and write the output to a file. If you don’t want this thread to block, read and write from another thread.