如何指定批处理文件中的输入结束

发布于 2024-10-08 06:37:29 字数 285 浏览 4 评论 0原文

我有一个程序 x.exe,它等待用户的输入并读取直到文件末尾。我想从批处理文件中调用它。

x.exe My Text Goes Here and goes and goes and goes and how to say it ends?

当我运行它时,似乎 x.exe 正在运行,它已经消耗了我给它的字符串,但它仍然等待更多输入。如何在批处理文件中指定 EOF 字符?

当我从控制台运行它时,我按 Ctrl+Z 指定 eof。如何对 bat 文件执行同样的操作? 谢谢。

I have a program x.exe it waits for an input from user and reads till end of file. I want to call it from a batch file.

x.exe My Text Goes Here and goes and goes and goes and how to say it ends?

When I run it, it seems as though x.exe is running, it has already consumed the string I gave it, but it is still pending for more input. How do I specify the EOF character in a batch file?

When I run it from console, I press Ctrl+Z to specify eof. How do I do the same with a bat file?
Thanks.

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

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

发布评论

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

评论(1

稍尽春風 2024-10-15 06:37:29
echo "My Text Goes Here and goes and goes and goes and how to say it ends?" | x.exe

您现在执行此操作的方式实际上并不将文本作为输入发送到您的程序,而是将它们作为命令行参数传递(传递给主函数的字符串数组 - 它是 char* argv[ ] 即 argc 元素长)。

使用echo将其打印到标准输出,然后使用管道将echo的标准输出连接到程序的标准输入。

echo "My Text Goes Here and goes and goes and goes and how to say it ends?" | x.exe

The way you're doing it now doesn't actually send the text to your program as input, it passes them as command line arguments (the array of strings that is passed to your main function - it is char* argv[] that is argc elements long).

Use echo to print it to standard output, and then use the pipe to connect the standard output of echo to the standard input of your program.

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