java/bin/sh:1:未找到触摸屏
当使用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, "");
}
# 1 楼答案
你确定在
touch
和aaa
之间有一个合适的空格(0x20)吗当您尝试使用参数从
sh
运行一个不存在的命令时,shell中的“not found”消息不包含以下参数:试着在没有Java代码的情况下从命令行运行命令,看看它是否可以从那里运行