Is it possible that print() and the bsh prompt are being sent out on different streams ?
i.e.  System.out and System.err ?  Depending on the OS and the order of flushing them,
that could result in mixed and unordered output.
 
 
----- Original Message -----
From: J Ramesh Kumar
To: Daniel Martin
Cc: beanshell-users@lists.sourceforge.net
Sent: Monday, July 30, 2007 5:17 AM
Subject: Re: [Beanshell-users] Delayed print on the bsh Console

Hi Daniel,

Thanks for your valuable inputs. I have cross checked my program and both threads (getBshPrompt() thread and get() method print Thread) are same. I haven't span a new background thread.  During my analysis of this issue, I found the following peculiar behavior. I have overwrite getBshPrompt() command which will be used to customize my bsh prompt. Following are the content of getBshPrompt.bsh file,

getBshPrompt()
{
        print("before returning prompt...\n");
        return "EMH CM CLI > ";
}

I am expecting the following print whenever I press enter,

EMH CM CLI >
before returning prompt...
EMH CM CLI >

But I got the following output,

EMH CM CLI >
EMH CM CLI > before returning prompt...

I appreciate your help on this.

Regards,
Ramesh

Daniel Martin wrote:
J Ramesh Kumar <rameshj@adventnet.com> writes:

  
I have implemented a command named "get()". I have put some prints in
the get() command implementation. Most of the times, my prints come
after the prompt is printed. But I am not facing this issue in the
bsh.Interpretor. The output is like,
    

This depends on what program it is that is using bsh.  As you mention,
you don't see this same problem with bsh.Interpreter.

It seems that your prints are running in a separate thread from
whatever thread is displaying the prompts.  This is either because the
program reading the bsh command is running the bsh command being read
in a background thread or because your get() function is running stuff
in a background thread.

To see if it's the program you're using, try this:

for (int i : new int[] {1,2,3}) {print(i);Thread.sleep(1000);}

If that comes out as:
*EMH CLI >*for (int i : new int[] {1,2,3}){print(i);Thread.sleep(1000);}
*EMH CLI >*1
2
3

Then the problem has to do with the program using bsh and how it uses
it; if you can't modify the program that is using bsh, then you're out
of luck.

If, however, you get the 1 .. 2 ... 3 nicely between prompts, then the
problem is in your get() function, and you have to see where it's
running stuff in a background thread.  If the background thread is
unavoidable, you may want to see about using the Thread.join() method
in the foreground thread before your get() function exits.

  


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/


_______________________________________________
Beanshell-users mailing list
Beanshell-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/beanshell-users