В чем может быть проблема с кодом ниже, когда передано с command = touch aaa
, оно выдает /bin/sh: 1: touch aaa: not found
Вот код
boolean isWindows = System.getProperty("os.name")
.toLowerCase().startsWith("windows");
String [] cmd ={"-c", command};
CommandLine cmdLine = new CommandLine("/bin/sh");
cmdLine.addArguments( cmd,false );
if (isWindows) {
DefaultExecutor exec = new DefaultExecutor();
exec.setExitValue(0);
exec.setWorkingDirectory(new File(System.getProperty("user.home")));
int exitCode = exec.execute(cmdLine);
return new Response(exitCode, "");
} else {
DefaultExecutor exec = new DefaultExecutor();
exec.setExitValue(0);
exec.setWorkingDirectory(new File(System.getenv("HOME")));
int exitCode = exec.execute(cmdLine);
return new Response(exitCode, "");
}