Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / March 2005

Tip: Looking for answers? Try searching our database.

java.io.InputStream

Thread view: 
The Print Dude - 18 Mar 2005 01:18 GMT
I have an issue...

Consider the following snippet of code:

       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;
               System.out.println("Executing: " + command);
      Process tracert_proc = Runtime.getRuntime().exec(command);

      InputStream cmdout = tracert_proc.getInputStream();

      char c;
      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);
       }

I like the getInputStream class, but the problem is that it returns an int.
Since the result of my exec(command) should be a tracert then
I would want to see characters coming back to me.  Is there another
class/method combination I can use to do this?

Thanks
klynn47@comcast.net - 18 Mar 2005 04:18 GMT
I'm not sure I understand your question. The method getInputStream
returns a reference to an InputStream that you can read with an
InputStreamReader and read efficiently with a BufferedReader. Then you
can read from the stream with readLine
Daniel Tahin - 21 Mar 2005 10:51 GMT
Hi!

I guess, this was discussed below under "Capturing output from a
command" ...

> I have an issue...
>
[quoted text clipped - 44 lines]
>
> Thanks


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.