Re: ?s about Process Class
From: publius36 (publius36_at_yahoo.com)
Date: 07/08/04
- Next message: Roedy Green: "Re: Command line invocation in Windows"
- Previous message: Roedy Green: "Re: Reseting ArrayList iterator to first item?"
- In reply to: Chris Smith: "Re: ?s about Process Class"
- Next in thread: John C. Bollinger: "Re: ?s about Process Class"
- Reply: John C. Bollinger: "Re: ?s about Process Class"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 08 Jul 2004 19:21:26 GMT
ipconfig is work well for test purposes..
however the code frag you gave...
> InputStream in = process.getInputStream();
> BufferedInputStream buf = new BufferedInputStream(in);
> InputStreamReader r = new InputStreamReader(buf);
won't work : syntax ---> public InputStreamReader(InputStream in)
you are supplying a BufferedInputStream object and not the required
InputStream object
the correct code frag should be :
InputStream in = nhProcess.getInputStream();
InputStreamReader r = new InputStreamReader(in);
BufferedReader buf = new BufferedReader(r);
to achieve what you intended.
even though the syntax for BufferedReader is
public BufferedReader(Reader obj)
I think it works because the Reader object is the superclass
of all readers, and why it can handle the InputStreamReader object.
"Chris Smith" <cdsmith@twu.net> wrote in message
news:MPG.1b57298c8b8f26929896e2@news.altopia.net...
> publius36 wrote:
> > Well I can't get it to work and being the presistant bugger that i am I
have
> > switch tactics so I can more up the learning curve.
> > I have resorted to just trying to display the output of mem.exe.
>
> Okay. I have a number of comments. Many of them are not necessarily
> related to the specific problem you've got, but here they are anyway.
>
> First,
>
> > while((ch = buf.read()) != -1)
> > {
> > System.out.print((char)ch);
> > }
>
> BufferedInputStream reads bytes. System.out writes characters (it's a
> rather confused case, actually, but if you call its "print" method that
> it writes characters.) Bytes and characters are *not* the same thing.
> The right way to do this is to use an InputStreamReader to convert from
> bytes to characters.
>
> InputStream in = process.getInputStream();
> BufferedInputStream buf = new BufferedInputStream(in);
> InputStreamReader r = new InputStreamReader(buf);
>
> then
>
> while ((ch = r.read()) != -1)
> {
> System.out.print((char) ch);
> }
>
> then
>
> r.close();
>
> The way you've written your code only happens to work because your
> system default character encoding matches the byte-truncation of unicode
> for all characters that you read. As the system's default encoding
> changes, or as you start working with programs that output different
> characters such as accented or non-latin characters, the code will
> suddenly break. InputStreamReader solves that problem.
>
> > It works the first time I run the class file with java test.
> > However, the next attempt hangs and requires a system restart inorder to
get
> > the code to display the results.
>
> Actually, it probably requires killing the runaway NTVDM process on
> Windows. There is a bug in modern 32-bit Windows operating systems
> running a 16-bit process in a way that doesn't attach it to a physical
> console, and this causes NTVDM to become confused. Since mem.exe is
> just a test program for you, the answer is to choose a different program
> to test with. Try "ipconfig.exe" instead.
>
> --
> www.designacourse.com
> The Easiest Way to Train Anyone... Anywhere.
>
> Chris Smith - Lead Software Developer/Technical Trainer
> MindIQ Corporation
- Next message: Roedy Green: "Re: Command line invocation in Windows"
- Previous message: Roedy Green: "Re: Reseting ArrayList iterator to first item?"
- In reply to: Chris Smith: "Re: ?s about Process Class"
- Next in thread: John C. Bollinger: "Re: ?s about Process Class"
- Reply: John C. Bollinger: "Re: ?s about Process Class"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|