首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何启动控制台进程

如何启动控制台进程
EN

Stack Overflow用户
提问于 2011-05-28 23:52:06
回答 2查看 673关注 0票数 0

我正在从我的windows应用程序运行一个进程,该进程是控制台exe文件。我使用了以下代码:

代码语言:javascript
复制
void compilerWindow::runClicked()
{
    proc = new QProcess(this);
    QString name = "C:\\qtEcoolCompiler\\qt\\vm.exe";

    QStringList args = QStringList() << "codeGeneration.vm";

    connect(proc, SIGNAL(readyRead()),
                  SLOT(readFromProc()));
    connect(proc, SIGNAL(error(QProcess::ProcessError)),
                  SLOT(procError(QProcess::ProcessError)));
    connect(proc, SIGNAL(finished(int)),
                  SLOT(procFinished()));

    outputBrowser->clear();
    outputBrowser->append("Begining Of Execution");

    proc->start(name, args);
    proc->waitForFinished();
}

但问题是控制台没有显示(没有打开),procFinished()将被调用,控制台直到那时才会打开。

我该怎么做?

EN

回答 2

Stack Overflow用户

发布于 2011-05-29 00:31:49

尝试system()函数;它将像从windows cmd运行一样运行命令。

票数 0
EN

Stack Overflow用户

发布于 2013-11-28 04:53:18

首先是The console won't open with QProcess in windows

代码语言:javascript
复制
Note: Windows intentionally suppresses output from GUI-only applications to
inherited consoles. This does not apply to output redirected to files or 
pipes. To forward the output of` GUI-only applications on the console 
nonetheless, you must use SeparateChannels and do the forwarding yourself 
by reading the output and writing it to the appropriate output channels.

因此,您应该使用readAllStandardOutput()或readChannel()或其他提供的函数读取进程stdout。我不知道vm.exe做了什么,但是假设路径是正确的,并且procError( int )永远不会被调用...进程正在正常运行并完成。

如果你想使用Readyread()信号,你需要set the read channel。但我建议改用readyReadStandardOutput()信号。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6162707

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档