簡體   English   中英

/ bin / sh:1:未找到觸摸

[英]/bin/sh: 1: touch not found

當使用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, "");
}

你確定touchaaa之間有一個合適的空間(0x20)嗎?

當您嘗試使用參數從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

嘗試從命令行運行命令,不使用Java代碼,並查看它是否可以從那里運行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM