I know we can run a linux terminal command in a java program like following code shows a "ls" command for the home directory.
String[] cmd1 = {
"/bin/sh",
"-c",
"cd ../.. && ls"};
Process child1 = Runtime.getRuntime().exec(cmd1);
child1.waitFor();
final BufferedReader is = new BufferedReader(new InputStreamReader(child1.getInputStream()));
String line;
while ((line = is.readLine()) != null) {
System.out.println("output is: "+line);
}
But I have no idea what "/bin/sh" and "-c" mean for? I searched it online and somebody used "bash" or else. And if I run the command as "cd ../.. && ls" only, I will get the same result.
So if there is a command in terminal as "txl -o output inputFile", where "txl" is a tool installed, how to write in in java? I tried
String[] cmd1 = {
"/bin/sh",
"-c",
"cd ../.. && txl -o output inputFile"};
But could not get the result. I add "cd ../.." to go to the home directory first from the working space because txl is installed in the home bin directory.
Can anyone give me some suggestions?
EDIT:
I made a stupid spelling error and the command in this format works!