如何在执行批处理

如何在执行批处理

本文介绍了如何在执行批处理(.Bat)文件时取消命令提示符窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



可以告诉我如何在没有命令提示符的情况下静默运行我的批处理文件吗?



我有2个批处理文件,mybatchfile1和mybatchfile2。我从代码中调用mybatchfile1,从mybatchfile1调用mybatchfile2。



我试过以下代码但是没有用。





Hi,
Could any tell me how do I run my batch file silently without command prompt?

I have 2 batch files, mybatchfile1 and mybatchfile2. i am calling mybatchfile1 from code and mybatchfile2 from mybatchfile1.

I have tried following code but it not working.


Process process = new Process();
process.StartInfo.FileName = processInfo.FileName; //(mybatchFile.bat)
process.StartInfo.WorkingDirectory = processInfo.WorkingDirectory;
process.StartInfo.UserName = processInfo.UserName;
process.StartInfo.Password = processInfo.Password;
process.StartInfo.Arguments = processInfo.Arguments;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.StartInfo.UseShellExecute = false;
process.Start();

推荐答案

process.StartInfo.RedirectStandardOutput = true;
process.OutputDataReceived += new DataReceivedEventHandler(ProcessOutputHandler);
process.StartInfo.RedirectStandardError = true;
process.ErrorDataReceived += new DataReceivedEventHandler(ProcessOutputHandler);





和定义处理程序





and defining a handler

private void ProcessOutputHandler(object sendingProcess, DataReceivedEventArgs stdOutErrorLine)
{
   if (!String.IsNullOrEmpty(stdOutErrorLine.Data))
   {
        // Use stdOutErrorLine.Data or not 
   }
}



这篇关于如何在执行批处理(.Bat)文件时取消命令提示符窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 14:08