0

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 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.

Allen L
  • 127
  • 1
  • 11
  • Can VBScript even do this? You'll need to at least post code that shows how you started the C++ program and how you write to stdout. – Hans Passant Aug 16 '10 at 08:01
  • Thank youm Hans. The C++ code consists simple printf() (write to stdout, in the case of console app it goes to the screen) and scanf() (read from stdin) calls. – Allen L Aug 16 '10 at 08:41
  • Are you sure the pipe you write to is the stdin of the script? Code would be helpful. – Frank Osterfeld Aug 16 '10 at 09:17
  • Am I missing something? Aren't printf/ scanf referring to StdIn/ StdOut? – Allen L Aug 16 '10 at 10:04
  • I don't know whether it's related your problem, but it's better to avoid using `scanf`. http://c-faq.com/stdio/scanfprobs.html . And again, *post code* (including the VBScript). – jamesdlin Aug 16 '10 at 10:07
  • If any answer was correct or helpful please accept or upvote. And see also: http://stackoverflow.com/questions/2075886/capturing-output-from-wshshell-exec-using-windows-script-host/9063149#9063149 – Ben Feb 11 '12 at 21:25

1 Answers1

0

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.

Ben
  • 34,935
  • 6
  • 74
  • 113