Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#:调用批处理文件并跳过";按任意键继续“;_C#_Winforms_Batch File - Fatal编程技术网

C#:调用批处理文件并跳过";按任意键继续“;

C#:调用批处理文件并跳过";按任意键继续“;,c#,winforms,batch-file,C#,Winforms,Batch File,我正在调用C#程序中的批处理文件。但是批处理文件有一个“暂停”,所以我得到了“按任意键继续”窗口。我无法编辑批处理文件。有没有办法跳过这个?我正在使用下面的代码()并对其进行处理,但运气不好 提前谢谢大家 int exitCode; string command = "test.bat" ProcessStartInfo processInfo; Process process; string path = @"C:\test\test"; processInfo = new ProcessS

我正在调用C#程序中的批处理文件。但是批处理文件有一个“暂停”,所以我得到了“按任意键继续”窗口。我无法编辑批处理文件。有没有办法跳过这个?我正在使用下面的代码()并对其进行处理,但运气不好

提前谢谢大家

int exitCode;
string command = "test.bat"
ProcessStartInfo processInfo;
Process process;
string path = @"C:\test\test";

processInfo = new ProcessStartInfo("cmd.exe", "/c " + command);
processInfo.WorkingDirectory = path;
processInfo.CreateNoWindow = true;
processInfo.UseShellExecute = false;
processInfo.RedirectStandardError = true;
processInfo.RedirectStandardOutput = true;

process = Process.Start(processInfo);
process.WaitForExit();

string output = process.StandardOutput.ReadToEnd();
string error = process.StandardError.ReadToEnd();

exitCode = process.ExitCode;

MessageBox.Show("output>>" + (String.IsNullOrEmpty(output) ? "(press any key to continue...)" : output));
MessageBox.Show("error>>" + (String.IsNullOrEmpty(error) ? "(none)" : error));
MessageBox.Show("ExitCode: " + exitCode.ToString(), "ExecuteCommand");
process.Close();
试一试

processInfo = new ProcessStartInfo("cmd.exe", "/c \"break|" + command+"\"");
试一试

processInfo = new ProcessStartInfo("cmd.exe", "/c \"break|" + command+"\"");


建议:一,。尝试使用ShellExecute,2。尝试将switch/q与cmdI一起使用,我会亲自解析批处理文件,并运行每个命令。。。如果你真的需要dos提示,还有一个sendkey。@Psi尝试了这两种方法,但都没有成功。啊,sry,没有看到。因此,你唯一能做的就是:读取.bat,删除内存中的
暂停
,将结果保存到一个临时位置,然后执行它。我的意思是,批处理文件只是一个文本文件,只需读取行,然后像执行命令一样执行它们。。或者删除暂停,保存到本地的临时批处理文件,然后运行这个该死的东西。尝试使用ShellExecute,2。尝试将switch/q与cmdI一起使用,我会亲自解析批处理文件,并运行每个命令。。。如果你真的需要dos提示,还有一个sendkey。@Psi尝试了这两种方法,但都没有成功。啊,sry,没有看到。因此,你唯一能做的就是:读取.bat,删除内存中的
暂停
,将结果保存到一个临时位置,然后执行它。我的意思是,批处理文件只是一个文本文件,只需读取行,然后像执行命令一样执行它们。。或者只是删除暂停,保存到本地临时批处理文件,然后运行该死的东西。它不会完成批处理文件。它存在于-1@Besiktas-你试过用附加引号更新吗?我的错。刚用新的引号试过,现在返回代码是255@Besiktas在命令提示符下执行
cmd/c“break | test.bat”
时会发生什么情况?
255
通常意味着输出到不存在的管道,在这种情况下可能意味着找不到test.bat。是否确定执行目录?它没有完成批处理文件。它存在于-1@Besiktas-你试过用附加引号更新吗?我的错。刚用新的引号试过,现在返回代码是255@Besiktas在命令提示符下执行
cmd/c“break | test.bat”
时会发生什么情况?
255
通常意味着输出到不存在的管道,在这种情况下可能意味着找不到test.bat。你确定执行目录吗?