Http://blogger.org.cn/blog/more.asp? Name = nrzj & id = 4280
Using System;
Using System. Diagnostics;
Namespace Tipo. Tools. Utility
{
/// <Summary>
/// Common doscommand operations
/// </Summary>
Public class DosCommand
{
Private Process process = null;
Private string _ errmsg;
Public DosCommand ()
{
Process = new Process ();
Process. StartInfo. FileName = "cmd.exe ";
Process. StartInfo. UseShellExecute = false;
Process. StartInfo. RedirectStandardInput = true;
Process. StartInfo. RedirectStandardOutput = true;
Process. StartInfo. RedirectStandardError = true;
Process. StartInfo. CreateNoWindow = false;
Process. Start ();
}
// Check whether a file or directory exists
Public string exist (string path)
{
Process. StandardInput. WriteLine (string. Format ("dir \" {0} \ "", path ));
Process. StandardInput. WriteLine ("exit ");
_ Errmsg = process. StandardError. ReadToEnd ();
Return _ errmsg;
}
}
}