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
Post a Comment