Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

It's all about Stream...  RSS feed

 
hudoq Dee
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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 ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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...
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!