开发者

redirecting output of a cmd to a file

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:

  1. capture the output of the ls in Java (capturing the Process input stream, as it's confusingly named) and create a file yourself
  2. use "sh -c 'ls whatever > file'". The -c executes everything following it in a shell, including redirection.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜