2017-04-14 24 views
1

を実行することはできません: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_pa​​ssword.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(); 
} 
+0

JavaはWindowsにUnixシェルスクリプトを実行する機能を与えません。 UnixサービスをWindows(Services For UnixまたはUbuntu)にインストールする方法がありますが、このプロセスはWindowsのインストール/設定の一部です。 –

+0

@ElliottFrisch Thats興味があります。将来を知ってうれしい... – finnrayment

答えて

0

は、 "bashの"、(おそらくgitのbashのを、)を実行しているbashのように、パラメータとして "get_encrypted_pa​​ssword.sh" を渡しますあなたのスクリプトを実行します。

+0

奇妙なことに、エラー2は "ファイルが見つかりません"で、私はいくつかの異なるエラーが予想されます。または、Windowsが何らかの "get_encrypted_pa​​ssword.sh.exe"または "get_encrypted_pa​​ssword.sh.bat"を見つけて実行しようとしていたために、エラーが「ファイルが見つかりません」。 –

+0

返信いただきありがとうございます。 :) – Prosp

関連する問題