调用cmd执行命令

注意:对于命令行,若路径中带有空格时,如D:\My Documents\a.txt时,将找不到此路径,可采用以下两种方法:  
1,加引号如:"D:\My Documents\a.txt"
2,  变缩写:采用8个字符缩写,即写头六个字母(略去空白),另加波浪号和1 改成:D:\MyDocu~1
  
try
{

    Process p = new Process();

    p.StartInfo.FileName = "cmd";

    p.StartInfo.UseShellExecute = false;

    p.StartInfo.RedirectStandardInput = true;

    p.StartInfo.RedirectStandardOutput = true;

    p.StartInfo.RedirectStandardError = true;

    p.StartInfo.CreateNoWindow = true;

    p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

    p.Start();

    string strOutput = null;

    string s = @"F:\DownLoad\wenku\FlashPaper2.2\FlashPaper2.2\FlashPrinter.exe " + "\"" + Server.MapPath("~//test.doc") + "\" -o \"" + Server.MapPath("~//test2.swf") + "\"";
   
    p.StandardInput.WriteLine(s);

    p.StandardInput.WriteLine("exit");

    strOutput = p.StandardOutput.ReadToEnd();

    Console.WriteLine(strOutput);

    p.WaitForExit();

    p.Close();

   lblMessage.Text = "success";

}

catch (Exception ex)
{

   lblMessage.Text = ex.ToString();

}