Forum Stats

  • 3,759,048 Users
  • 2,251,494 Discussions
  • 7,870,477 Comments

Discussions

cmd syntax to get messages

843798
843798 Member Posts: 24,864
edited Jun 21, 2001 12:36PM in Java Runtime Environment (JRE)
Hi,
I am trying to write java code that will execute commands in the dos window and read the output from the commands.
For example, I need to use a program called verifier. I think I know how to call the verifier program in my java code, but I don't know how to read the message it gives. The verifier prints out a message telling me if it is okay or not in the dos window. How do I get my java code to recognize that message so it knows what to do next?

Thanks!!

Comments

  • 843798
    843798 Member Posts: 24,864
    You should use Runtime.getRuntime().exec("command") to execute the command. To get the output of the command, read the OutputStream returned by calling the getOutputStream method on the Process object that the exec method returns.
  • 843798
    843798 Member Posts: 24,864
    thanks!

    but after I get the Process from the exec command, if I use OutputStream,... there are only write methods? How would I read the Outputstream?

    InputStream has read methods... I tried using that method with

    p.waitFor(); //Process p
    numberResultBytes = theInputStream.available();
    //InputStream theInputStream

    but numberResultBytes is always 0.

    thanks again for the help.
This discussion has been closed.