我想運行執行與Java類「DefaultExecutor」 shell腳本中的命令,但我得到這個錯誤:的Java不能運行程序CreateProcess的錯誤= 2
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();
}
Java不會賦予Windows運行Unix shell腳本的能力;有一種方法可以在Windows中安裝Unix服務(Unix或Ubuntu的服務),但是該過程是Windows安裝/配置的一部分。 –
@ElliottFrisch這很有趣。很高興知道未來... – finnrayment