runtime.exec - Java - Command Execution in Runtime -


i tried out simple program execute linux command @ run time. following program gets compiled , runs without error, text file not getting created intended.is there wrong in program?

import java.io.*; class executejava {     public static void main(string args[])     {             string historycmd = "cat ~/.bash_history >> documents/history.txt";             try             {                     runtime runtime = runtime.getruntime();                     process proc = runtime.exec(historycmd);             }             catch(exception e)             {                     system.out.println(e);             }     } } 

the append operator >> meant interpreted part of command shell. use

string[] historycmd =             { "bash", "-c", "cat ~/.bash_history >> documents/history.txt"}; 

Comments

Popular posts from this blog

java - How to Configure JAXRS and Spring With Annotations -

visual studio - TFS will not accept changes I've made to a Java project -

php - Create image in codeigniter on the fly -