如何为进程设置标准输出。 [英] How to set standard output for a process.

查看:132
本文介绍了如何为进程设置标准输出。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在创建两个APF应用程序。

APP-1:家长申请。

APP-2:儿童申请。



情景:

根据条件从APP-1调用APP-2。 br />
我正在使用Process.Start和StartInfo.Arguments来调用APP-2并将一些数据传递给它。



APP-2获取该数据并对其进行处理。我想在APP-1关闭后从APP-2中捕获最终数据。



以下是代码。



Hi,

I'm creating two APF applications.
APP-1: Parent Application.
APP-2: Child Application.

Scenario:
APP-2 is invoked from APP-1 based on a condition.
I'm using Process.Start and StartInfo.Arguments to invoke the APP-2 and pass some data to it.

APP-2 takes that data and works on it. There is a Final Data which I want to capture from APP-2 within APP-1 once it's closed.

Following is the code.

string parameter = "INVK://param1/value1/param2/value2/";

			System.Diagnostics.Process launchAuthorApp = new System.Diagnostics.Process();
			launchAuthorApp.StartInfo.FileName = @"C:\APP2.exe";
			launchAuthorApp.StartInfo.Arguments = parameter;
			launchAuthorApp.OutputDataReceived += launchAuthorApp_OutputDataReceived;
			launchAuthorApp.Start();
			while (!launchAuthorApp.StandardOutput.EndOfStream)
			{
				string line = launchAuthorApp.StandardOutput.ReadLine();
			}







如何设置APP-2的输出?



Kinldy回复。



谢谢,

Abhishek



我的尝试:



我试过




How do I set the output for APP-2?

Kinldy respond.

Thanks,
Abhishek

What I have tried:

I Tried

System.Diagnostics.Debug.WriteLine("Output 123");



但不工作。

我不确定我是否朝着正确的方向前进。


but not working.
I'm not sure if I'm moving in right direction.

推荐答案

我认为你必须重定向输出并使用 Console.WriteLine



Mhm ...也许类似这个 [ ^ ]可以帮到你



在你的APP-1中

I think you have to redirect the output and use Console.WriteLine.

Mhm... maybe something like this[^] could help you

In your APP-1
var launchAuthorApp = new System.Diagnostics.Process {
    StartInfo = {
          FileName               = @"C:\APP2.exe",
          UseShellExecute        = false,
          RedirectStandardOutput = true,
          Arguments              = "INVK://param1/value1/param2/value2/"
    }
};

launchAuthorApp.Start();

Console.WriteLine(launchAuthorApp.StandardOutput.ReadToEnd());





和APP-2(例如)



And in APP-2 (as example)

static void Main(string[] args) {
    Console.WriteLine(args[0]);
}


这篇关于如何为进程设置标准输出。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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