0

My code:

Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.FileName = Environment.CurrentDirectory + @"\PsExec\PsExec.exe";
p.StartInfo.Arguments = @"\\server-0 cmd /c wmic process get description,executablepath";
p.Start();
string output = p.StandardOutput.ReadToEnd();
string errormessage = p.StandardError.ReadToEnd();
p.WaitForExit();

The console window does not close itself. When I close it manually, I see (in output):

Description             ExecutablePath                                             

I don't see any other line! But if I write the same in the console:

psexec \\server-0 cmd /c wmic process get description,executablepath

I see:

Description             ExecutablePath
System Idle Process
System
smss.exe
csrss.exe               C:\Windows\system32\csrss.exe
wininit.exe             C:\Windows\system32\wininit.exe
csrss.exe               C:\Windows\system32\csrss.exe
...

I tried some ideas like: Thread.Sleep(...), per line reading, -accepteula, EnableRaisingEvents / OutputDataReceived (it does not call), -d flag (no output), UseShellExecute=true (works, but I couldn't hide the console window)...

Why do I receive only the first row (in the C# code above)? What should I change to receive the same content I see in the console?

Sorry for the bad English. Thanks for your answers.

dda
  • 6,030
  • 2
  • 25
  • 34
Dmitry
  • 581
  • 1
  • 4
  • 15
  • Have you asked a question??? – Michael Bray Jul 06 '13 at 02:58
  • @MichaelBray yes, i need help – Dmitry Jul 06 '13 at 03:00
  • My point was, as it is clear your English isn't great, that you *haven't* asked a question. Please ask a specific question about your code, if you hope to receive an answer. As it is, all you have said is "please fix it". – Michael Bray Jul 06 '13 at 03:05
  • See here: [How do I ask a good question?](http://stackoverflow.com/help/how-to-ask) – Michael Bray Jul 06 '13 at 03:06
  • @MichaelBray, yes, thanks; yeap, my english is bad, sorry; the question is why i receive only first row (in c# code above), what should i change to receive the same i see in console? – Dmitry Jul 06 '13 at 03:21
  • 1
    Maybe this question has the answer for you - http://stackoverflow.com/questions/1145969/processinfo-and-redirectstandardoutput – BillH Jul 06 '13 at 03:58

1 Answers1

-1

Use delegating. Rise event on output received and capture the data. I did the same