如何启动控制台进程

发布于 2024-11-10 09:38:10 字数 785 浏览 3 评论 0原文

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

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() ,并且在此之前控制台不会打开。

我应该怎么办?

I'm working on running a process from my windows application, the process is console exe file. I'm using the following code :

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();
}

But the problem is the console isn't showing up (not opening) and the procFinished() will be called and console wont open until then.

What should I do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

舟遥客 2024-11-17 09:38:10

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

try the system() function; it will run the commands as if run from windows cmd

蓝天白云 2024-11-17 09:38:10

首先 控制台不会在 Windows 中使用 QProcess 打开

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() 或其他提供的函数之一读取进程标准输出。我不知道 vm.exe 做了什么,但假设路径正确并且 procError( int ) 从未被调用......该进程正在正确运行并完成。

如果要使用Readyread()信号,需要设置读取通道。但我建议使用 readyReadStandardOutput() 信号代替。

Firstly The console won't open with QProcess in windows

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.

So you should be reading the processes stdout with readAllStandardOutput() or readChannel() or one of the other provided functions. I have no idea what vm.exe does, but assuming the path is correct and procError( int ) is never being called.... the process is running and finishing correctly.

If you want to use the Readyread() signal, you need to set the read channel. But I would suggest using the readyReadStandardOutput() signal instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文