を実行することはできません:Javaは、私はJavaクラス「DefaultExecutor」でシェルスクリプトを実行し、コマンドを実行したいのですが、私はこのエラーを取得するプログラムのCreateProcessエラー= 2
Cannot run program "get_encrypted_password.sh" (in directory "C:\Temp\scripts"): CreateProcess error=2 specified file not found".
スクリプトがでうまく動作git bash。
誰かが私が間違っていることを教えてもらえますか? Windowsで実行することができない代わりに、 "get_encrypted_password.sh" を実行する
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シェルスクリプトを実行する機能を与えません。 UnixサービスをWindows(Services For UnixまたはUbuntu)にインストールする方法がありますが、このプロセスはWindowsのインストール/設定の一部です。 –
@ElliottFrisch Thats興味があります。将来を知ってうれしい... – finnrayment