Capturing output from a command
From: J (squibbies43_at_hotmail.com)
Date: 03/20/05
- Next message: Tom Dyess: "Re: from j2sdk to j2ee ?"
- Previous message: John: "Re: overriding Close operation in WindowAdapter"
- Next in thread: Anthony Borla: "Re: Capturing output from a command"
- Reply: Anthony Borla: "Re: Capturing output from a command"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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);
}
}
- Next message: Tom Dyess: "Re: from j2sdk to j2ee ?"
- Previous message: John: "Re: overriding Close operation in WindowAdapter"
- Next in thread: Anthony Borla: "Re: Capturing output from a command"
- Reply: Anthony Borla: "Re: Capturing output from a command"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|