Boris Raznikov
Boris Raznikov

Reputation: 2453

calling command line from .NET application

I want to call from a c# application a command line starting from it an application and retrieve the stat from it.

I did this but something is missing:

ProcessStartInfo psf = new ProcessStartInfo("cmd.exe", "/C time");
psf.WindowStyle = ProcessWindowStyle.Hidden;
psf.RedirectStandardOutput = true;
psf.UseShellExecute = false;
psf.CreateNoWindow = true;
Process p = Process.Start(psf);
StreamReader sr = p.StandardOutput;
p.WaitForExit();

What is wrong ?

Upvotes: 0

Views: 1793

Answers (2)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039438

To get the system time I would recommend you using the DateTime structure:

string time = DateTime.Now.ToString("hh:mm:ss.fff");
Console.WriteLine(time);

Upvotes: 1

Lukas Pokorny
Lukas Pokorny

Reputation: 1558

Try passing "/c time /t" instead of "/c time".

Upvotes: 2

Related Questions