cantas
cantas

Reputation: 114

How to get output of cmd in c# and dotnet

I try to send commend to cmd and get output. I'm sure it sent but I cannot get the output.

 ProcessStartInfo startinfo = new ProcessStartInfo();
        startinfo.FileName = @"C:\Users\mehmetcan\Desktop\adt-bundle-windows-x86-20130917\sdk\platform-tools\adb.exe";
        startinfo.Arguments = @"devices";
        startinfo.RedirectStandardOutput = true;
        startinfo.RedirectStandardError = true;
        startinfo.UseShellExecute = false;

        // Note: declare process as a variable in the class as it needs to be used in the event handlers
        process = new Process();
        process.StartInfo = startinfo;

It returns : "123456 devices " How can get it in a string?

Upvotes: 0

Views: 158

Answers (1)

Nickolay Olshevsky
Nickolay Olshevsky

Reputation: 14160

You should read it via

string output = process.StandardOutput.ReadToEnd();

Upvotes: 1

Related Questions