I tried a simple program to execute a Linux command at runtime. But the following program compiles and runs without any error, but the text file is not created as intended. Is there something wrong with this 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); } } }
source share