尝试将输入批量写入正在运行的控制台应用程序时出错 [英] Error while trying to write inputs to running console app with a batch

查看:197
本文介绍了尝试将输入批量写入正在运行的控制台应用程序时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要与批处理文件一起执行的exe文件.

I have an exe file that I want to execute with a batch file.

Exe文件是第三方控制台应用程序,将提示您输入三次.

Exe file is a third party console app that will prompt for input three times.

所以我想用一个空行someText和someOtherText填充它

So I want to fill it in with an empty line, someText and someOtherText

(echo. echo someText echo someOtherText) | call config.exe remove

但是我遇到了这个错误:

But I'm getting this error:

Cannot read keys when either application does not have a console or when console input has been redirected. Try Console.Read.

可能是问题所在,请至少建议搜索方向?

What could be the issue, please advise at least the direction to search?

即使尝试执行一个更简单的命令,我也会遇到相同的错误:

I have the same error even if try to execute a simpler command like:

echo. | call config.exe remove

推荐答案

您的config.exe完全不接受重定向.它需要真实的控制台缓冲区.

Your config.exe does not accept redirection at all. It requires real console buffers.

  1. 如果要使其自动化,可以创建另一个控制台应用程序,

  • 使用 CreateProcessW启动您的config.exe
  • 使用 STD_INPUT_HANDLE https://docs.microsoft.com/zh-cn/windows/win32/api/fileapi/nf-fileapi-writefile"rel =" nofollow noreferrer> WriteFile (ASCII,\n分隔行)或 WriteConsoleInputW (如果需要Unicode字符)
  • 写入完成后,只需等待config.exe终止并返回退出代码
    • start your config.exe using CreateProcessW
    • write your lines to STD_INPUT_HANDLE using WriteFile (ASCII, \n separated lines) or WriteConsoleInputW (if you need unicode characters)
    • after write is complete, just wait for config.exe termination and return exit code
      1. 另一个更简单的选项是 ConEmu终端(我是作者).有 GuiMacro脚本,可从控制台轻松使用.因此,您可以从提示符处运行,也可以将其包装在批处理文件中(在ConEmu中运行):

      1. Another simpler option is ConEmu terminal (I'm the author). There is GuiMacro scripting which could be easily used from console. So you could just run from your prompt or wrap in in batch file (run in ConEmu):

      ConEmuC.exe -GuiMacro打印"\ nsomeText \ nsome其他文本\ n"; & config.exe删除

      ConEmuC.exe -GuiMacro print "\nsomeText\nsome Other Text\n" & config.exe remove

      这篇关于尝试将输入批量写入正在运行的控制台应用程序时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆