简体   繁体   中英

How to get rid of the pause command in the batch file which is opened from the command prompt using c#

Below is the code for running the batch file from the command prompt. The problem is that there is a pause command in the batch file which is stopping the application and I am not able to proceed with the next step. Can some one give me an idea to fix this.

Process gacCOMprocess = new Process();
infoPageExecuteBatchFiles.PageText = "Running gacCOM.bat ";
infoPageExecuteBatchFiles.Refresh();
ProcessStartInfo gacCOMprocessStartInfo = new ProcessStartInfo();
gacCOMprocessStartInfo.FileName = PRES_TIER_PATH + "\\gacCOM.bat ";
gacCOMprocessStartInfo.UseShellExecute = false;
gacCOMprocessStartInfo.RedirectStandardOutput = true;
gacCOMprocessStartInfo.CreateNoWindow = true;
gacCOMprocessStartInfo.RedirectStandardInput = true;
gacCOMprocess.StartInfo = gacCOMprocessStartInfo;
gacCOMprocess.OutputDataReceived += new DataReceivedEventHandler(ExecuteBatchFilesHandler);
gacCOMprocess.Start();
gacCOMprocess.BeginOutputReadLine();
gacCOMprocess.WaitForExit();
gacCOMprocess.Close();

You could just add a parameter that you can pass along with the command line when you start the program. Then add a check for this parameter to each pause. That's what i did recently (assuming you can edit the batch file):

Set IsAutomated=%1

IF NOT %IsAutomated%==1 (
    echo Script was started manually.
    pause
)

That was because the script was still also run manually and in that case, the pause was needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM