代码之家  ›  专栏  ›  技术社区  ›  Abhisek Mishra

运行autosys批处理作业并在java中检查其状态

  •  1
  • Abhisek Mishra  · 技术社区  · 7 年前

    我需要运行autosys批处理作业,然后检查其状态,直到其状态更改为SU。 我已经编写了以下代码,但它给了我以下异常:

    CreateProcess error=2, The system cannot find the file specified
    

    代码:

    try {
                String[] cmds = {
                        "C:\\Folder_Path\\plink.exe -ssh username@Server -pw Password",
                        "sendevent -E FORCE_STARTJOB -j job-name"};
                Runtime r = Runtime.getRuntime();
                Process p = r.exec(cmds);
                InputStream std = p.getInputStream ();
                OutputStream out = p.getOutputStream ();
                InputStream err = p.getErrorStream ();
    
                Thread.sleep (5000);
                int value = 0;
                String output = "";
                if (std.available () > 0) {
                    System.out.println ("STD:");
                    value = std.read ();
                    //System.out.print ((char) value);
    
                    while (std.available () > 0) {
                        value = std.read ();
                        output+=(char) value;
    
                    }
                }
    
                if (err.available () > 0) {
                    System.out.println ("ERR:");
                    value = err.read ();
                    //System.out.print ((char) value);
    
                    while (err.available () > 0) {
                        value = err.read ();
                        output+=(char) value;
                    }
                }
                System.out.print (output);
                p.destroy ();
            }
            catch (Exception e) {
                e.printStackTrace ();
            }
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   NumeroUno    7 年前

    你的命令应该是:

    String[] cmds = {"C:\\Folder_Path\\plink.exe", "-ssh", "username@Server", "-pw", "Password", "sendevent", "-E", "FORCE_STARTJOB", "-j", "job-name"};
    

    第一个参数是可执行文件名。使用cmd时,由于找不到“C:\ Folder_Path\plink.exe-ssh username@Server-pw Password”,因此它出现错误。