.NET控制台输出和PSExec [英] .NET console output and PSExec

查看:100
本文介绍了.NET控制台输出和PSExec的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行PSExec Microsoft工具,其中Process类执行带有其自身输出的远程命令,如下所示:

I'm running PSExec Microsoft tool with Process class executing a remote command with its own output like this:

            Process p = new Process();

            string args = @"\\remotemachine -u someuser -p somepass wmic product get name";

            ProcessStartInfo ps = new ProcessStartInfo();
            ps.Arguments = args;
            ps.FileName = psExecFileName;
            ps.UseShellExecute = false;
            ps.CreateNoWindow = true;
            ps.RedirectStandardOutput = true;
            ps.RedirectStandardError = true;

            p.StartInfo = ps;
            p.Start();

            StreamReader output = p.StandardOutput;

            string output = output.ReadToEnd();

其中 wmic产品获得名称是远程运行的WMI工具,具有自己的输出列出远程计算机上所有已安装的应用程序。
因此,在 output 中,我看不到 wmic 的输出,同时在本地命令行中运行PSExec时,可以完全看到PSExec和远程启动WMIC的输出。
问题是,如何捕获本地计算机上的所有输出?我应该在单独的控制台中运行它并尝试将其附加到控制台以捕获所有输出吗?

where wmic product get name is WMI tool running remotely with its own output listing all installed applications on the remote machine. So, in the output I don't see the output of wmic, at the same time when I'm running PSExec in the command line locally, I can fully see the output of both PSExec and started remotely WMIC. The question is, how can I capture all the output on the local machine? Should I run it in a separate console and try to attach to the console to capture all the output?

更一般地说,如果简单地说,为什么在此过程中输出 StandardOutput 和直接运行PSExec时在控制台中不一样?

More generally, if put plainly, why is the output in the process StandardOutput and in the console when running PSExec directly not the same?

推荐答案

在控制台中,数据在控制台中显示同时写入 StandardOutput StandardError 的消息。

In the console, data written to both StandardOutput and StandardError is displayed in the console.

在您的程序中,您需要单独查看每个文件...尝试在末尾添加如下内容:

Within your program you need to look at each individually...try adding something like this at the end:

string error = p.StandardError.ReadToEnd();

这篇关于.NET控制台输出和PSExec的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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