Cannot read psexec output

S

sjoshi

Hi All

I'm trying to use the Process/ProcessStartInfo class to use
sysinternals psexec tool to run a remote command but I'm unable to get
the output. The same command thru a DOS window runs fine on a remote
server.

The code is very simple...

_logger.Debug(string.Format("Filename: {0} Args: {1}", pathToExe,
args));

pc = new Process();

pc.StartInfo.FileName = pathToExe;
pc.StartInfo.Arguments = args;
pc.StartInfo.CreateNoWindow = true;
pc.StartInfo.UseShellExecute = false;
pc.StartInfo.RedirectStandardOutput = true;

if (pc.Start())
{
output = pc.StandardOutput.ReadToEnd();

pc.WaitForExit(20 * 1000);
}

return output;

But the process seems to wait forever. I even tried getting the log of
the parameters namely pathToExe and args and then running it manually
and that ran fine.

Any hints are appreciated.

thanks
Sunit
 
K

Kerem Gümrükcü

Hi Sunit,

why reinvent the wheel? See here:

[Debugging Tools for Windows]
http://www.microsoft.com/whdc/devtools/debugging/installx86.mspx

It comes with a tool called "remote.exe" which can run a command
remotely and display its content (with interaction!) on your local system.
It's intended for the usage in driver development scenarios, but you can
use it wherever you think it will help you. And i think it is usefull in you
case,...

It just works fine and you dont have to redirect output stream with your
code.

BTW you should redirect any stream from the console to be able
to get any returned stream from the console output, this includes
also the errors and whatever your console outputs (socket, pipe,etc,...)

Regards

Kerem

---------
New Open Source Tools from me:
Calculate MD5 or SHA1 Hash for Files!
KHash Tools 1.0 Englisch:
http://download.chip.eu/de/KHash-Tools-1.0_1317168.html
http://entwicklung.junetz.de/projects/opensource/khashtools/khashtools v.1.0.zip
---------

Beste Grüsse / Best regards / Votre bien devoue

Kerem Gümrükcü
(e-mail address removed)

Best Quote: "Ain't nobody a badass with a double dose
of rock salt...", Kill Bill Vol.2

Latest Open-Source Projects: http://entwicklung.junetz.de
Sign my guestbook: http://entwicklung.junetz.de/guestbook/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top