0

I am trying to send a mail from Unix shell through a java program. I use Apache commons exec to do this.

The command is

mutt  -s "Subject of mail" email@domain.com < file.txt

And the Java code I use is

CommandLine cmdLine = CommandLine.parse("mutt");
cmdLine.addArgument("-s");
cmdLine.addArgument("Subject of mail");
cmdLine.addArgument("email@domain.com");
cmdLine.addArgument("<");
cmdLine.addArgument("file.txt");
DefaultExecutor executor = new DefaultExecutor();
int exitValue = 0;
try {
    exitValue = executor.execute(cmdLine);
} catch (IOException e) {
    e.printStackTrace();
}

But this code does not work. How to do input redirection using java

Ram Vibhakar
  • 255
  • 2
  • 5
  • 19

1 Answers1

2

Try executor.getStreamHandler().setProcessInputStream(new FileInputStream("file.txt"))

but take care of the filepath

Turo
  • 4,724
  • 2
  • 14
  • 27