簡體   English   中英

Java無法運行程序CreateProcess error = 2

[英]Java Cannot run program CreateProcess error=2

我想運行一個使用java類“DefaultExecutor”執行shell腳本的命令,但是我收到此錯誤:

Cannot run program "get_encrypted_password.sh" (in directory "C:\Temp\scripts"): CreateProcess error=2 specified file not found".

該腳本適用於git bash。

誰能告訴我我哪里做錯了?

public Entity updateWithEncryptedPassword(Entity entity) throws IOException {
    String password = entity.getPwd();

    String security_key = "00000000000000000000000000000000";

    String path = "C:/Temp/scripts"; 

    CommandLine commandLine = CommandLine.parse("get_encrypted_password.sh");

    commandLine.addArgument(password);

    commandLine.addArgument(security_key);

    String encrypted_password = Utils.runCommandAndGetOutput(commandLine, path);

    entity.setNewPwd(encrypted_password);

    return super.update(entity);
}

public static String runCommandAndGetOutput(CommandLine commandLine, String path) throws IOException {
    DefaultExecutor defaultExecutor = new DefaultExecutor();
    defaultExecutor.setExitValue(0);
    defaultExecutor.setWorkingDirectory(new File(path));

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream);

    defaultExecutor.setStreamHandler(streamHandler);

    defaultExecutor.execute(commandLine);

    return outputStream.toString();
}

不執行無法在Windows下運行的“get_encrypted_pa​​ssword.sh”,而是執行“bash”(可能是git bash)並將“get_encrypted_pa​​ssword.sh”作為參數傳遞給它,以便bash執行您的腳本。

暫無
暫無

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

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