I have a situation where I want (need) do send a file by e-mail at the execution of a given java program. The copy commands are executed fine either on Windows and Linux, however, mutt is not working when the execution is ordered on java. The command string is generated flawless, (I currently manually type the string printed to console to manually send the e-mail), however the Runtime.getRuntime.exec() is not executing it properly.
if (OS.indexOf("win") >= 0)
{
// windows
cmd = "cmd /C copy "+workbookFileName+" "+latestWorkbookFileName;
System.out.println("executing command windows: "+cmd);
Runtime.getRuntime().exec(cmd);
}
else
{
// others
cmd = "cp "+workbookFileName+" "+latestWorkbookFileName;
System.out.println("executing Linux: "+cmd);
Runtime.getRuntime().exec(cmd);
cmd = "echo \"This is the message body\" | mutt -a \""+workbookFileName+"\" -s \"message subject\" -- sqlinjection@domain.com";
System.out.println("executing Linux: "+cmd);
Runtime.getRuntime().exec(cmd);
System.out.println("bye");
}