Richie

Sometimes at night when I look up at the stars, and see the whole sky just laid out there, don't you think I ain't remembering it all. I still got dreams like anybody else, and ever so often, I am thinking about how things might of been. And then, all of a sudden, I'm forty, fifty, sixty years old, you know?

C#调用命令行

//开关/c表示执行完命令就退出
System.Diagnostics.Process cmd = System.Diagnostics.Process.Start("CMD.exe"@"/c xcopy c:\test1\*.* c:\test2 /Y /Q /S");
cmd.WaitForExit();
System.Diagnostics.Process.Start(
"CMD.exe"@"/c rd c:\test1 /s /q");

每个System.Diagnostics.Process.Start开启一个新的进程运行指定的程序,所以多个System.Diagnostics.Process.Start语句将进程启动后,命令执行的先后顺序我们无法把握。
上面使用cmd.WaitForExit();,确保第一个命令执行完毕之后再执行第二个。

posted on 2007-10-09 14:41  riccc  阅读(1698)  评论(0编辑  收藏  举报

导航