Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
The following code is used to start a Dos program.
C#
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.
Posted
Updated 28-Feb-10 15:34pm
v2

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?
 
Share this answer
 
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:

MIDL
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.

:)
 
Share this answer
 
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.
 
Share this answer
 
The same thing happens when I call voc2wav.exe directly rather than thru CMD.ExE. Another curious thing is that when a condition exists where a file exists that voc2wav is trying to write to and it asks whether to continue y/n. If you answer n, it terminates and the process terminates. When you answer y, it continues, does its work correctly but the process (Cmd.exe) never terminates. None of this funny result occurs when you exectue voc2wav using the command prompt window.
 
Share this answer
 
I've made progress on this. It appears that the length of the command line agruments (all the path/file specs) exceeded some limit and they were being truncated. Is there a way to expand that limit?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900