we are trying to re-direct the output of the list to a file using the below cmd(java) in ubuntu, Pls let us know if this works or not ?
Process p = Runtime.getRuntime().exec("ls -l >/home/blah blah/new.txt")
we are trying to re-direct the output of the list to a file using the below cmd(java) in ubuntu, Pls let us know if this works or not ?
Process p = Runtime.getRuntime().exec("ls -l >/home/blah blah/new.txt")
No it won't. The '>
' is part of the shell and as such executing ls
on its own won't help.
You can:
ls
in Java (capturing the Process
input stream, as it's confusingly named) and create a file yourself"sh -c 'ls whatever > file'"
. The -c
executes everything following it in a shell, including redirection.