我无法运行ssh-keygen.exe。输出表示构建成功,但是代码应执行.exe并显示应用程序。这是我的代码

import java.io.IOException;

public class SSHConnectPing {

    public static void main(String... args) throws IOException {
        try
        {
            Runtime.getRuntime().exec("C:\\ExecuteSSH\\ssh-keygen.exe");
        }
        catch(Exception exc)
        {
            System.out.println("error" + exc);/*handle exception*/
        }
    }
}


我该怎么办?请帮我。

最佳答案

谢谢杰森,现在我可以执行我的.exe应用程序了

我的代码现在是

package apacherunsshkeygen;

import java.io.IOException;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.ExecuteWatchdog;


public class ApacheRunSSHKEygen {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) throws IOException {

    try {

//        String line = "AcroRd32.exe /p /h " + file.getAbsolutePath();
    String line = "C:\\ExecuteSSH\\ssh-keygen.exe";
    CommandLine cmdLine = CommandLine.parse(line);
    DefaultExecutor executor = new DefaultExecutor();

    //watchdog
    executor.setExitValue(1);
    ExecuteWatchdog watchdog = new ExecuteWatchdog(60000);
    executor.setWatchdog(watchdog);

    int exitValue = executor.execute(cmdLine);
    }

    catch (Exception exc){

       System.out.println("error" + exc);/*handle exception*/}
    }


   }

09-11 19:54