forwarding output from the command to the console.
By "forwarding" I assume you mean printing the input you receive?
The prompt will appear on the console, but only after the input has been entered.
That because you can't print it until you have read it, and you won't be able to read it until readline (in the guise of the diamond operator <$fh>), returns, which it won't until it see a newline.
As many prompts are printed without a newline so that the users input goes on the same line as the prompt, the text of the prompt will not be dispatched into the pipe until a newline is seen, and that won't happen until the user enters one.
Given that you appear to be printing everything received from the command, the tee trick I offered would probably work well for you. You just allow tee to do the forwarding and you just gather the output within your program for whatever processing you need to do, rather than echoing it yourself. The only extra step required is to filter the prompt and user input from the datastream.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] [select] |
As many prompts are printed without a newline so that the users input goes on the same line as the prompt, the text of the prompt will not be dispatched into the pipe until a newline is seen, and that won't happen until the user enters one.
I think you hit the nail on the head. For some reason I was thinking that I had the same problem with multi-line prompts (i.e. none of the prompt was visible until after user input). On the contrary, I just tested my script with a program that generates a five line prompt and the entire prompt was visible prior to input.
I guess I'll have to read from the pipe with sysread or something like it. Thanks for your help!
| [reply] |
I guess I'll have to read from the pipe with sysread or something like it.
If you succeed in getting that to work please come back and post a sample.
I looked at the source of tee and it just uses (C) read() from stdin, and it seems to be able to read and echo the prompt in a timely fashion, but regardless of what I tried from perl (binmode :raw; read() or sysread()), I couldn't get it to work.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] [select] |