I have a small C++ console application which presents a menu then performs the chosen operation.
In addition, I've written a VBScript which runs over the StdOut (achieved by Exec) and enters to StdIn the values.
However when I'm trying to executet this script the开发者_如何学C console application is stuck in the scanf call and the script doesn't receive anything from the output. _flushall() doesn't help.
Does anyone have any idea?
Thanks.
This is very difficult from VBScript/Windows Scripting Host, as there is no non-blocking IO. In other words, there is no way to say "Read whatever is available right now, then return immediately".
- If you say ReadLine, it will read a line. If there is no line ready right now, it will wait for one.
- If you say ReadAll, it will read until the file handle is closed, i.e. until the program exits. It will not return until then.
It is possible to do this from script, provided you know EXACTLY what output the program will create in every circumstance.
In most situations it is better to set the program up in a non-interactive "batch" mode if possible, where the program accepts commands but without any need to respond to prompts.
精彩评论