sh -c "cd /home/dipankar/NetBeansProjects/TransBench/Hindi;./mat"
When executing following command in linux terminal its executes perfectly. However, when I am trying to run the same using java runtime its gives the following error :
ERROR>/home/dipankar/NetBeansProjects/TransBench/Hindi;./mat": -c: line 0: unexpected EOF while looking for matching `"'
ERROR>/home/dipankar/NetBeansProjects/TransBench/Hindi;./mat": -c: line 1: syntax error: unexpected end of file
Please help I am new to linux.
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("sh -c \"cd /home/dipankar/NetBeansProjects/TransBench/Hindi;./mat\"");
proc.waitFor();
Given the tag and the symptoms, I expect that you are using an exec
method that takes the command as a single String
.
That won't work. The problem is that the method uses a very simple scheme to "parse" the command string into a command name and arguments. It simply splits the string where there is whitespace ... ignoring any quoting, and any other shell stuff.
What you need to do is to use the overload that takes a String[]
; e.g.
....exec(new String[]{
"sh",
"-c",
"cd /home/dipankar/NetBeansProjects/TransBench/Hindi;./mat"
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With