Capturing output from a command

From: J (squibbies43_at_hotmail.com)
Date: 03/20/05


Date: Sun, 20 Mar 2005 02:55:29 GMT

I think I may have bitten off more than I can handle here but I thought it
would be interesting to try to write a Java program to parse my firewall log
and do traceroutes on all the IP addresses. I've done pretty well with it
so far, but the command that I am using, while it runs fine from the dos
prompt does not do what I expected it to when I run the code in my class.

Here is the method I have written to do the traceroutes. Basically, there's
an input file containing IP addresses and an output file where I store the
results.
I hate the way OE formats things when they come from Text Pad.
The line where I show what is executing is showing me a command that works
in the dos command window but the file I'm writing to does not
get created when the program runs.... Can anyone give me any ideas why not?
public static void traceIPs(String fileName, String outFileName)

{

       if ((fileName == null) || (fileName == ""))

            throw new IllegalArgumentException();

            String line;

            String command;

            try

                {

                        BufferedReader in = new BufferedReader(new
FileReader(fileName));

                        if (!in.ready())

                                throw new IOException();

                        while ((line = in.readLine()) != null)

                                {

                                    try

                                    {

                                            command =
"C:/WINDOWS/system32/tracert.exe " + line + " >> " + outFileName;

                                             System.out.println("Executing:
" + command);

                                            Process tracert_proc =
Runtime.getRuntime().exec(command);

                                            InputStream cmdout =
tracert_proc.getInputStream();

                                             int x;

                                            while (( x = cmdout.read())
!= -1)

                                            {

                                                    //System.out.print(x);

                                            }cmdout.close();

                                       } catch (IOException e)

                                {

                                            System.out.println("I died" +
"\n");

                    }

        }

            in.close();

    }

            catch (IOException e)

            {

                    System.out.println(e);

            }

    }



Relevant Pages

  • Re: Best ways to start off Java programs with C & RPG???
    ... Can you recommend some settings for a smallish Java program? ... What about the 'command to run' field? ... While such things run as a background task, ...
    (comp.sys.ibm.as400.misc)
  • Re: Best ways to start off Java programs with C & RPG???
    ... explanation that follows, which I'm doing from memory, doesn't help, let me ... On the command line enter CALL QCMD. ... let your Java program run as a separate job. ... While such things run as a background task, ...
    (comp.sys.ibm.as400.misc)
  • Re: Best ways to start off Java programs with C & RPG???
    ... let your Java program run as a separate job. ... If you can start the command from a green screen command line, ... so lines if you aren't passing any parameters) and call it from the RPG. ... While such things run as a background task, ...
    (comp.sys.ibm.as400.misc)
  • proc.getErrorStream never empties.
    ... When I run a java program which does a ... to run a process on Windows (aha, ... synthesized from the error code and contents of the error stream. ... but build up the command, see the end of the above eexception message for the ...
    (comp.lang.java.programmer)
  • Re: Simple Java Problem
    ... > Linux/Java configuration questions it seems ... > the helper needs to guess the actual problem ... better to have a working java program first than to learn the ... > of the command line. ...
    (comp.lang.java.help)