在Qt应用程序中运行Windows命令提示符命令 [英] Running windows command prompt commands in a Qt application

查看:108
本文介绍了在Qt应用程序中运行Windows命令提示符命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过Qt应用程序运行一个外部exe,该应用程序要求在Windows命令提示符下输入命令.

I need to run an external exe through Qt application which requires commands to be entered in windows command prompt.

  QString exePath = "C:\Windows\system32\cmd.exe";
  QProcess pro;
  pro.start(exePath);
  pro.execute("cmd.exe");

但是我得到的输出如下纯cmd提示

But I got output like below plain cmd prompt

但是我想要Windows命令提示符,例如预期的cmd

But I want windows command prompt like expected cmd

推荐答案

pro.start(exePath);
pro.execute("cmd.exe");

您不应同时使用这两种方法,QProcess :: execute是静态成员.

You should not use this two methods at same time, QProcess::execute is static member.

您需要启动分离的进程:

You need to start process detached:

QString exePath = "C:\Windows\system32\cmd.exe";
QProcess pro;
pro.startDetached(exePath);
pro.waitForStarted();
//Event Loop here

这篇关于在Qt应用程序中运行Windows命令提示符命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆