PSExec:将 C# 控制台应用程序输出重定向到 window/Diagnostics.Process?
因此,我编写了一个 C# 控制台应用程序,它将内容发送到控制台(在我的例子中,是一些 XML)。现在我使用 PsExec 从另一台机器调用该控制台应用程序;该调用工作正常,并以错误代码 0 退出(表示成功),但是,我无法检索/查看控制台应用程序写入命令行标准输出的输出。
我的调用看起来像这样:
"C:\Program Files\PSTools\psexec.exe"
<machineName>
-u <user>
-p <password>
"C:\..\..\consoleapp.exe"
-arg1 "value"
我注意到,当我运行此命令时,它会弹出打开和关闭速度非常快的 psexec 窗口(可能是我的控制台应用程序)之外的第二个窗口。我尝试添加 -i 标志、2>&1、>>C:output.txt 和 >C:\output.txt 重定向,但没有一个使我的控制台应用程序输出出现在原始版本中控制台窗口 [其中包含 psexec],也不将我的控制台应用程序输出转储到文件。
然而,这是一个中间目标,我试图将此输出重定向到 System.Diagnostics.Process 对象,该对象仅设法将 psexec 输出重定向到 stderror (即“PSexec 连接到...以代码 0 退出” )。标准输出是空白的,我想包含我的控制台应用程序输出。
有什么建议吗?
So I've written a C# console app that spits stuff to the console (in my case, some XML). Now I'm calling that console app from another machine using PsExec; the call works fine and exits with error code 0 (meaning success), however, I cannot retrieve/see the output written to the command line standard output by my console app.
My call looks something like:
"C:\Program Files\PSTools\psexec.exe"
<machineName>
-u <user>
-p <password>
"C:\..\..\consoleapp.exe"
-arg1 "value"
I've noticed that when I run this, it pops open a second window other than the psexec window (that presumably is my console app) that opens and closes very fast. I've tried adding the -i flag, the 2>&1, >>C:output.txt, and >C:\output.txt redirects, none which get my console app output to appear in the original console window [that has psexec in it], nor dump my console app output to file.
This is an intermediate goal however, I'm trying to redirect this output into a System.Diagnostics.Process object, which has only managed to redirect just the psexec output to stderror (i.e. "PSexec connecting to... exited with code 0"). The stdout is blank, which I'd like to contain my console app output.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您需要某种进程间通信。实现这一目标的一种方法是创建命名管道。看看这篇文章,也许它会为你指明以后的方向。
http://www.switchonthecode.com/tutorials/interprocess -使用csharp中的命名管道进行通信
Sounds like you need some kind of interprocess communication. One way to achieve that is by creating named pipes. Have a look at this article, maybe it'll point u in the direction u r after.
http://www.switchonthecode.com/tutorials/interprocess-communication-using-named-pipes-in-csharp