Plivo通过Windows命令提示符和java发送单个消息

时间:2017-09-06 09:44:33

标签: java cmd sendmessage plivo

您好我正在尝试运行传递给runExternalProgram的命令。当我通过cmd运行命令时,它成功了,我能够收到一条消息但是当我运行java程序时,没有错误问题,但没有收到任何消息。我该如何解决这个错误?

    String Command ="cmd /c start java -classpath C:/Users/admin/Desktop/Smsworkspace/sendmessage/src;C:/Users/admin/Desktop/Smsworkspace/sendmessage/src/plivo-java-3.0.9-jar-with-dependencies.jar sendmessage.SendSMS2 +xxxxx +xxxxx CS";

runExternalProgram

public HashMap runExternalProgram_Windows(String Command) {
    String _LOC = "[SB_Utilities: runExternalProgram_Windows]";
    System.out.println(_LOC + "1.0");
    System.out.println("Command is: "+ Command);
    String line;

    InputStream stderr = null;
    InputStream stdout = null;

    HashMap _m = new HashMap();

    try {

        Process process = Runtime.getRuntime ().exec (Command);
        System.out.println("Process is: " + process);
        Worker worker = new Worker(process);
        System.out.println("Worker is: " + worker);
        worker.start();
        try {
            worker.join(180000);
            if (worker.exit == null) 
            {
                throw new Exception();                  
            }
        } 
        catch(Exception ex) {
            ex.printStackTrace();
            _m.put("LOG_ERROR_EXTERNAL", "180 second time out...check connection");
            return _m;
        } 
        finally {
            process.destroy();
        }

        stderr = process.getErrorStream ();
        stdout = process.getInputStream ();

        String _log_output = null;

        // clean up if any output in stdout
        BufferedReader brCleanUp = new BufferedReader (new InputStreamReader (stdout));
        System.out.println("Outcome is: "+brCleanUp.readLine());
        while ((line = brCleanUp.readLine ()) != null) {

            if (_log_output==null) {
                _log_output = line + "\n";
            } else {
                _log_output = _log_output + line + "\n";                    
            }
        }

        brCleanUp.close();

        _m.put("LOG_OUTPUT", _log_output);

        String _log_error = null;
        // clean up if any output in stderr
        brCleanUp=new BufferedReader (new InputStreamReader (stderr));
        System.out.println("Outcome error is "+brCleanUp.readLine());
        while ((line = brCleanUp.readLine ()) != null) {
            if (_log_error==null) {
                _log_error = line + "\n";
            } else {
                _log_error = _log_error + line + "\n";                  
            }
        }

        brCleanUp.close();          
        _m.put("LOG_ERROR_EXTERNAL", _log_error);

    } catch (Exception e) {
        e.printStackTrace();
    }

    return _m;      

}

0 个答案:

没有答案