Dos程序不会使用CMD.EXE和System.Diagnostics.Process类退出 [英] Dos program won't exit using CMD.EXE and System.Diagnostics.Process Class

查看:243
本文介绍了Dos程序不会使用CMD.EXE和System.Diagnostics.Process类退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码用于启动Dos程序.

 System.Diagnostics.Process process1;
            process1 =  System.Diagnostics.Process();
            process1.StartInfo.FileName = " ;
            process1.StartInfo.Arguments = "  + Convert.ToString(shortPathVocLoc)+
                "  + Convert.ToString(shortPathWavLoc);
            process1.StartInfo.UseShellExecute =  false ;
            process1.StartInfo.CreateNoWindow =  false ;
            process1.StartInfo.WorkingDirectory = Convert.ToString(shortPathVoc2Wav);
            process1.Start();
            process1.WaitForExit();
            MessageBox.Show(" ); 



当我运行它时,该过程将启动并执行其任务,但不会终止.当我使用命令提示符"窗口并手动运行完全相同的程序时,该程序将运行并终止.

任何人都不知道是什么原因造成的. Windows XP Sp3.

谢谢.

解决方案

我的猜测是voc2wav正在退出,但cmd不在,这就是process1正在等待的东西.


您好,
而不是调用cmd.exe并将其传递给/c voc2wav ...作为参数?


您好,

我还记得另一种情况,有人必须将包含空格的参数传递给命令提示符,这会引起问题.解决方案是将参数用引号引起来:

 process1.StartInfo.Arguments = "  + Convert.ToString(shortPathVocLoc)+ "  + Convert.ToString(shortPathWavLoc)+ " ; 



我不确定这是否对您有帮助,请尝试一下.

:)


感谢您的建议.似乎DOS程序本身是古怪的.当文件位于工作目录中时,它可以工作,但是当文件位于其他目录中时,则有问题,使其看起来像是cmd.exe问题.


The following code is used to start a Dos program.

System.Diagnostics.Process process1;
            process1 = new System.Diagnostics.Process();
            process1.StartInfo.FileName = "cmd";
            process1.StartInfo.Arguments = "/c voc2wav.exe "+Convert.ToString(shortPathVocLoc) +
                " " + Convert.ToString(shortPathWavLoc);
            process1.StartInfo.UseShellExecute = false;
            process1.StartInfo.CreateNoWindow = false;
            process1.StartInfo.WorkingDirectory = Convert.ToString(shortPathVoc2Wav);
            process1.Start();
            process1.WaitForExit();
            MessageBox.Show("exited");



When I run it, the process starts and performs its task but it doesn''t terminate. When I use the Command Prompt window and run the exact same thing manually, the program runs and terminates.

Anyone have any idea what is causing this. Windows XP Sp3.

Thanks.

解决方案

My guess would be that voc2wav is exiting, but cmd is not and that''s what process1 is waiting for. Instead of calling cmd.exe and passing it /c voc2wav ... for the arguments what happens if you call voc2wav directly?


Hi,

I recall another case where someone had to pass arguments containing spaces to the command prompt, which caused problems. The solution was to wrap the arguments in quotation marks:

process1.StartInfo.Arguments = "\"/c voc2wav.exe "+Convert.ToString(shortPathVocLoc) + " " + Convert.ToString(shortPathWavLoc) + "\"";



I''m not sure if it helps in your case, but give it a try.

:)


Thanks for the advice. It seems the that DOS program itself is quirky. It works when the files are in the working directory but has problems when they are in other directories making it look like it is a cmd.exe problem.


这篇关于Dos程序不会使用CMD.EXE和System.Diagnostics.Process类退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆