Since your arguments contain spaces, you cannot rely on the built-in tokenization. To avoid this, use exec(String[])
rather than exec(String)
. For example, for this command:
/home/saj/g2p/mosesdecoder-master/bin/moses -f \
/home/saj/g2p/working/binarised-model/moses.ini 'T W O N E I G H T'
You would do this:
String args[] = new String[] {
"/home/saj/g2p/mosesdecoder-master/bin/moses",
"-f",
"/home/saj/g2p/working/binarised-model/moses.ini",
"T W O N E I G H T" };
Process p = r.exec(args);
Also, regarding piping and redirection, note that these are handled by the shell. In order to run a command line such as echo '/home/saj/' | ls
from Java, you should execute a shell and pass this to the shell as an argument; for example:
String args[] = new String[] { "/bin/sh", "-c", "echo '/home/saj/' | ls" };
Process p = r.exec(args);