如何写的另一个应用程序的标准输入? [英] How to write to the stdin of another app?

查看:162
本文介绍了如何写的另一个应用程序的标准输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有读取StandardError的的处理的模块。一切工作正常,但我想做些不同的事。我不知道如何重定向标准输入,如原生方式:

I have a module that reads the StandardError of a process. Everything works fine, but I want to do something different. I don't know how to redirect stdin like the native way:

app1.exe -someargs | app2.exe -someargs

在哪里APP2 APP1读取所有标准输出在标准输入。

Where app2 reads all the stdout of app1 in its stdin.

推荐答案

看一看以下(无论是在被发现的MSDN参考文档的 System.Diagnostics程序命名空间):

Have a look at the MSDN reference documentation for the following (both to be found in the System.Diagnostics namespace):

<一个href="http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.redirectstandardinput.aspx"相对=nofollow> ProcessStartInfo.RedirectStandardInput
有一个示例,演示如何启动一个子进程,并直接写入它的标准输入。

ProcessStartInfo.RedirectStandardInput.
There's an example showing how to start a child process and write directly to its standard input.

为了您的具体的例子,这里是你如何设置的东西了:

  1. APP1 的开始的 APP2 的一个子进程使用进程类(见上面的链接)。

  1. app1 starts app2 as a child process using the Process class (see links above).

APP1 的写的 APP2 的的标准输入通过写的了 .StandardInput 进程对象关联的 APP2 的。

app1 writes to app2's standard input by writing to the .StandardInput stream of the Process object associated with app2.

APP2 的只是读取它的标准输入线(例如通过到Console.ReadLine())。

app2 just reads lines from its standard input (e.g. via Console.ReadLine()).

这篇关于如何写的另一个应用程序的标准输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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