Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Currently i'm using that one for executing some things in a cmd.

C#
string[] strCmdText = { "/C pdflatex letter_of_application.tex", "/C xelatex curriculum_vitae.tex", "/C biber curriculum_vitae.bcf", "/C xelatex curriculum_vitae.tex" };
            
            foreach (string cmd in strCmdText)
            {
                Process process = new Process();
                ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.WindowStyle = ProcessWindowStyle.Hidden;
                startInfo.FileName = "cmd.exe";
                startInfo.Arguments = cmd;
                process.StartInfo = startInfo;
                process.Start();
            }


Now the problem is, that if the compiler works this lines, it opens 4 cmds and executes it directly.

How can i tell him, that it should wait until the previous process is ended?

What I have tried:

<pre lang="c#">string[] strCmdText = { "/C pdflatex letter_of_application.tex", "/C xelatex curriculum_vitae.tex", "/C biber curriculum_vitae.bcf", "/C xelatex curriculum_vitae.tex" };
            
            foreach (string cmd in strCmdText)
            {
                Process process = new Process();
                ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.WindowStyle = ProcessWindowStyle.Hidden;
                startInfo.FileName = "cmd.exe";
                startInfo.Arguments = cmd;
                process.StartInfo = startInfo;
                process.Start();
            }
Posted
Updated 22-Sep-20 9:25am
Comments
Perić Željko 22-Sep-20 14:31pm    
https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.process.hasexited?view=netcore-3.1#System_Diagnostics_Process_HasExited

1 solution

Try:
C#
process.WaitForExit();
 
Share this answer
 
Comments
Sascha Manns 22-Sep-20 15:31pm    
Thank you very much. That works as expectede :-)
OriginalGriff 22-Sep-20 15:56pm    
You're welcome!

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