prePEND到标准输入 [英] Prepend to stdin

查看:106
本文介绍了prePEND到标准输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个交互式命令行程序,我们会打电话的Program.exe。虽然它的运行,我可以键入一堆做不同的事情不同的命令。我们会打电话给他们:DOA,DOB,DOC,并退出。现在,事实证明,我想的Program.exe做的第一件事是的总是的DOA。我想保存几个按键并自动运行的Program.exe在启动命令DOA。不幸的是,我不能只通过,因为谁创造的Program.exe没有实现该功能的命令行DOA。

I've got an interactive command line program that we'll call program.exe. While it's running, I can type in a bunch of different commands that do different things. We'll call them: doA, doB, doC, and quit. Now, as it turns out, the first thing I want to do in program.exe is always doA. I'd like to save a few keystrokes and automatically have program.exe run the command doA upon startup. Unfortunately, I can't just pass "doA" on the command line because whoever created program.exe didn't implement that feature.

我看到它的方式,我有几个选择:

The way I see it, I have a few options:


  • 写另一个程序调用的Program.exe,写DOA它的标准输入,然后钩住它自己的标准输入到PROGRAM.EXE的标准输入和挂钩的Program.exe的sdtout到它自己的标准输出。这可能会工作,但我想看看是否有不需要编译器的解决方案

  • Write another program that calls program.exe, writes doA to its stdin, then hooks it's own stdin to program.exe's stdin and hooks program.exe's sdtout to it's own stdout. This will probably work, but I'd like to see if there's a solution that doesn't require a compiler

使用一些批处理文件魔力果酱DOA成的Program.exe的标准输入。这是我已经得到了有关问题的一部分。以下是我试过到目前为止:

Use some batch file magic to jam doA into program.exe's stdin. This is the part that I've got questions about. Here's what I've tried so far:

回声DOA | Program.exe文件

这工作,在执行的Program.exe DOA,但我不能键入任何其他命令PROGRAM.EXE。回声霸占了的Program.exe的标准输入

This works, in that program.exe executes doA, but then I can't type any other commands to program.exe. Echo is hogging up program.exe's stdin

更多|回声DOA | Program.exe文件

这也适用,并得到一点点接近我后。执行的Program.exe DOA,我看到DOA的输出。我还可以输入更多命令,但我没有看到这些命令的输出。此外,当我发送quit命令,终止的Program.exe(我猜的),但我仍然停留在更多命令,我可以继续键入行,直到我打了CTRL + C。

This also works and gets a little closer to what I'm after. program.exe executes doA and I see the output from doA. I can also type in additional commands, but I don't see the output from these commands. Furthermore, when I send the quit command, program.exe terminates (I guess), but I'm still stuck in the "more" command and I can keep typing lines until I hit ctrl+c.

问题:是否有另一种方法做什么,我想用一个bat文件?从概念上讲,我觉得我需要两个流(键盘和文字DOA)合并成一个,并传递到Program.exe文件,但我可能是遥远。

The Question: Is there another way to do what I'm trying to do with a bat file? Conceptually, I think I need to combine two streams (the keyboard, and the literal "doA") into one and pass that into program.exe, but I could be way off.

推荐答案

首先,更多|回声DOA | Program.exe文件不会做你认为它。
发送的 DOA 回声后没有这些管道阶段连接在一起,它,而创造完美的水槽 - 这就是为什么你没有看到你的命令的响应。他们无处可去,而且不会的Program.exe 执行。我不认为有一个简单的方法来实现您直接从命令行想要的东西,但它可以通过小批量的文件,可以轻松解决。创建一个批处理文件,说 args.bat

First, more | echo doA | program.exe does not do what you think it does. After sending doA echo does not connect those pipe stages together, it rather creates perfect sink - that's why you do not see your commands echoed. They go nowhere and are not executed by program.exe. I don't think there is a simple way to achieve what you want directly from command line, but it can be easily resolved by using small batch file. Create a batch file, say args.bat:

@echo off 
echo First command
more

现在通过运行程序 ARGS | Program.exe文件

这篇关于prePEND到标准输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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