Plivo sending a single message through windows command prompt and java

108 views Asked by At

Hi i am trying to run this command that is passed on to the runExternalProgram. When i ran the command through cmd, it was successful and i was able to receive a message but when i run the java program, there was no error issue but no message was received. How should I go about solving this error?

    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

There are 0 answers