简体   繁体   English

如何在使用C#从命令提示符处打开的批处理文件中删除暂停命令

[英]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. 那是因为脚本仍然还是手动运行,在这种情况下,需要暂停。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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