在C#中,如何执行多句dos命令?

来源:百度知道 编辑:UC知道 时间:2024/05/06 11:31:17
例如
cd c:\program files\test
copy ":\exe\try.exe" "c:\program files\test" /y
c:\program files\test\try.exe
如何在C#中运行?不要写在文件中然后读入,应为有些密码我想写在里面
process.start()?
那样不是我要是有100句的话就出现100个command窗口?

private void abc()
{

Process p = new Process();

p.StartInfo.FileName = "cmd.exe";

p.StartInfo.UseShellExecute = false;

p.StartInfo.RedirectStandardInput = true;

p.StartInfo.RedirectStandardOutput = true;

p.StartInfo.RedirectStandardError = true;

p.StartInfo.CreateNoWindow = true;
p.Start ();

p.StandardInput.WriteLine("dir");
p.StandardInput.WriteLine("exit");
p.StandardInput.WriteLine("cd c:\");
p.StandardInput.WriteLine("exit");
p.StandardInput.WriteLine("dir");
p.StandardInput.WriteLine("exit");
p.StandardInput.WriteLine("cls");
p.StandardInput.WriteLine("exit");

p.Close ();
}