C# 如何使用c执行重复的dos命令#

C# 如何使用c执行重复的dos命令#,c#,c#-4.0,C#,C# 4.0,我使用下面的代码和c#在我执行记事本的注释行中执行doss命令,在我尝试执行excel的注释行中执行doss命令,但是没有人运行。如果我从记事本或excel中对任何一个进行注释,它就会执行。我想一个接一个地执行dos命令,看前一个命令是否完成了它的过程 通过两次设置Arguments属性,可以将“/C记事本”替换为“/C excel”。进程正在启动cmd.exe并仅将“/C excel”作为参数传递给它 我怀疑cmd.exe在作为“/C”参数传递时找不到Excel exe。这可以解释为什么你看不

我使用下面的代码和c#在我执行记事本的注释行中执行doss命令,在我尝试执行excel的注释行中执行doss命令,但是没有人运行。如果我从记事本或excel中对任何一个进行注释,它就会执行。我想一个接一个地执行dos命令,看前一个命令是否完成了它的过程


通过两次设置Arguments属性,可以将“/C记事本”替换为“/C excel”。进程正在启动cmd.exe并仅将“/C excel”作为参数传递给它

我怀疑cmd.exe在作为“/C”参数传递时找不到Excel exe。这可以解释为什么你看不到任何东西在执行。您可能需要指定Excel的完整路径

如果要同时执行记事本和Excel,需要先设置一个参数,然后为每个应用程序调用
Start
,一个接一个地启动它们

大概是这样的:

System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
process.StartInfo = startInfo;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/C notepad";
process.Start();
startInfo.Arguments = "/C {Insert the full path to Excel exe}excel";
process.Start();
System.Diagnostics.ProcessStartInfo startInfo = new ProcessStartInfo();
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo = startInfo;

startInfo.FileName = "notepad";
process.Start();

startInfo.FileName = "excel";
process.Start();
或者,您可以启动从进程启动的两个应用程序,而不是作为cmd.exe的参数启动<代码>进程本身就是cmd.exe。这将使操作系统有更好的机会使用Windows路径变量找到应用程序

大概是这样的:

System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
process.StartInfo = startInfo;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/C notepad";
process.Start();
startInfo.Arguments = "/C {Insert the full path to Excel exe}excel";
process.Start();
System.Diagnostics.ProcessStartInfo startInfo = new ProcessStartInfo();
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo = startInfo;

startInfo.FileName = "notepad";
process.Start();

startInfo.FileName = "excel";
process.Start();

现在执行两个进程thanx Linos Pechos…它帮助了我..好的,但当我试图放置startInfo.WindowStyle=System.Diagnostics.ProcessWindowStyle.Hidden;它只执行一个。你能告诉我如何把dos输出转换成字符串吗?比如string str=“Dos commans”等。