启用控制台应用程序的输出到脚本

发布于 2024-09-14 15:42:24 字数 213 浏览 2 评论 0原文

我有一个小型 C++ 控制台应用程序,它显示一个菜单,然后执行所选操作。

此外,我还编写了一个 VBScript,它在 StdOut(由 Exec 实现)上运行并将值输入到 StdIn。

但是,当我尝试执行此脚本时,控制台应用程序卡在 scanf 调用中,并且脚本没有从输出中接收任何内容。 _flushall() 没有帮助。

有人知道吗?

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南城追梦 2024-09-21 15:42:24

这对于 VBScript/Windows Scripting Host 来说非常困难,因为没有非阻塞 IO。换句话说,没有办法说“阅读现在可用的任何内容,然后立即返回”。

  • 如果你说 ReadLine,它会读取一行。如果现在没有线路准备好,它将等待一条线路。
  • 如果你说ReadAll,它将读取直到文件句柄关闭,即直到程序退出。在那之前它不会返回。

如果您确切地知道程序在每种情况下将创建什么输出,则可以从脚本中执行此操作。

在大多数情况下,如果可能的话,最好将程序设置为非交互式“批处理”模式,其中程序接受命令但不需要响应提示。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文