[英]/bin/sh: 1: touch not found
What could be the problem with the code below, when passed with command = touch aaa
当使用
command = touch aaa
传递时,下面的代码可能会出现什么问题
it throws /bin/sh: 1: touch aaa: not found
它抛出
/bin/sh: 1: touch aaa: not found
Here's the code 这是代码
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, "");
}
Are you sure there is a proper space (0x20) between touch
and aaa
? 你确定
touch
和aaa
之间有一个合适的空间(0x20)吗?
When you try to run a non-existent command from sh
with a parameter, the 'not found' message from the shell does not include the parameter: 当您尝试使用参数从
sh
运行不存在的命令时,shell中的“未找到”消息不包含参数:
% sh -c 'touchx aaa'
sh: 1: touchx: not found
% dash -c 'touchx aaa'
dash: 1: touchx: not found
% bash -c 'touchx aaa'
bash: touchx: command not found
% busybox sh -c 'touchx aaa'
sh: touchx: not found
Try to run your command from the command line, without the Java code, and see if it works from there. 尝试从命令行运行命令,不使用Java代码,并查看它是否可以从那里运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.