执行cmd然后卡住了,怎么办呀?谢谢了,大家帮忙看下.
如果执行cmd或者command这些命令然后就会在p.StandardOutput.ReadToEnd();这里卡住...
现在我解决的方法就是
这样加个时间,一旦3秒后强行结束,但是p.StartInfo.CreateNoWindow = true;就不管用了,
p.StartInfo.CreateNoWindow = false;就可以..
现在我解决的方法就是
public static string executeCmd(string command)
{
string strRst = "0";
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.StandardInput.AutoFlush = true;
p.StandardInput.WriteLine("@echo off");
p.StandardInput.WriteLine(command);
p.StandardInput.WriteLine("exit");
System.Timers.Timer timer = new System.Timers.Timer(3000);
timer.Start();
timer.Elapsed += delegate(object sender, System.Timers.ElapsedEventArgs e)
{
p.CloseMainWindow();
timer.Enabled = false;
timer.Close();
};
strRst = p.StandardOutput.ReadToEnd();
timer.Enabled = false;
timer.Close();
strRst = strRst.Substring(strRst.IndexOf(command) + command.Length);
strRst = strRst.Substring(0,strRst.Length - 8);
if (p.StandardError.ReadToEnd() != "")
{
strRst = p.StandardError.ReadToEnd();
}
p.WaitForExit();
p.Close();
return strRst;
}
这样加个时间,一旦3秒后强行结束,但是p.StartInfo.CreateNoWindow = true;就不管用了,
p.StartInfo.CreateNoWindow = false;就可以..
...全文
相关推荐
Java执行cmd命令两种实现方法解析
主要介绍了Java执行cmd命令两种实现方法解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
python执行CMD指令,并获取返回的方法
今天小编就为大家分享一篇python执行CMD指令,并获取返回的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
cmd下运行php脚本
其实蛮简单的 我的php安装目录在 d:\php 那么 运行 cmd >d: >cd php 要让工作目录指向php.exe的安装文件夹 然后就可以用php指令了 比如 在该文件夹下面新建一个test.php <?php echo “test”;?> >php test.php 看运行成功了吧。 您可能感兴趣的文章:Nginx和PHP-FPM的启动、重启、停止脚本分享在命令行下运行PHP脚本[带参数]的方法PHP命令行脚本接收传入参数的三种方式如何使用Linux的Crontab定时执行PHP脚本的方法PHP教程之PHP中shell脚本的使用方法
Windows server 2019安装JDK.docx
Windows server 2019 64位操作系统安装jdk时安装jre进度条卡住,等待很长时间也不继续
cmd脚本-bat批处理-显示进度.zip
cmd脚本-bat批处理-显示进度.zip


