• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

It's all about Stream...

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi' this is really makes me feel so upset. Why every time i try to execute WindowsExec file.
There's no error in code but the output not correctly.

WindowsExec.java :


outputer.java :


response.java :

maintest.java :

This is the illustration :
1. Execute WindowsExec
2. Maintest executed from WindowsExec. (see WindowsExec source).
3. Display the output.

The output should be like this : (see maintest source to check)
1. Print Insert : and wait input from user.
2. User write some input and press enter.
3. Read input from user and display it.
4. Program terminate.

But what i got, the output are like this : (this is not correctly)
1. Wait input from user. (see maintest source,the firstline should be print "Insert :",not waiting some input).
2. User write some input and press enter
3. print Insert : and read input from user and display it.
4. Program terminate.

Why the output become like that? (Conversation between WindowsExec and maintest not correctly).
Insert : should appear in the first line of the output.

How to get the right conversation between WindowsExec and maintest?

I hope my question easy to understand.

Thanks....
[ December 07, 2006: Message edited by: hudoq Dee ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, there are all sorts of subtleties here that I could critique, but I'm not going to, because I think I can answer your specific question pretty clearly. Whenever you call System.out.print() to print a prompt so you can accept input on the same line, you must immediately call System.out.flush() to force the output to appear; otherwise the symptom is exactly what you describe. Due to line buffering, you won't see the prompt until after the user presses the "Enter" at the end of their input.

But it sure seems like it would have been easier to just get "maintest" working the right way first when started from the command line by itself, yeah?
 
hudoq Dee
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> Whenever you call System.out.print() to print a prompt so you can accept input on the same line, you must immediately call System.out.flush() to force the output to appear.

Where should i put System.out.flush() to get the correct output? cos i try to declare that in file response.java after System.out.println(line). The output still same.

Can you give me an example where should i put System.out.flush()?

> Well, there are all sorts of subtleties here that I could critique.

Please, go on.cos i'm really upset with this.

Thanks before...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic