How to execute shell script and save in text file command through java in linux -


i m using linux.

i want call small executable application java command line called "wmic". needs input query. output stored in text file in specific directory.

when use command in linux terminal

echo "hello world" >> /home/kannan/hello.txt 

the output stored in hello.txt file.

but when call command java

process p = runtime.getruntime().exec("echo \"hello world\" >> /home/kannan/hello1.txt"); 

the output not created hello1.txt file

please 1 me.

thanks in advance.

use processbuilder. makes easy redirect output of command file shown below:

new processbuilder("echo", "hello").redirectoutput(new file("output.txt")).start(); 

if want append output file:

new processbuilder("echo", "hello").redirectoutput(redirect.appendto(new file("output.txt"))).start(); 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -