如何启动控制台进程
How to start a console process
我正在从我的windows应用程序运行一个进程,该进程是console 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(),在此之前控制台不会打开。
我该怎么办?
尝试system()函数;它将像从windows cmd 运行一样运行命令
首先控制台不会在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()或其他提供的函数之一读取进程stdout。我不知道vm.exe做什么,但假设路径是正确的,并且永远不会调用procError(int)。。。。进程正在正确运行和完成。
如果要使用Readyread()信号,则需要设置读取通道。但我建议使用readyReadStandardOutput()信号。
相关文章:
- boost::进程间消息队列引发错误
- C++:将控制台输出存储在宏中更好吗
- 在Qt Creator中,如何在连接到正在运行的进程后查看控制台输出
- 如何防止父进程在孩子死后丢失控制台输入?
- 有没有办法为使用 Boost 生成的进程创建新的控制台窗口
- 来自 c++ 服务的 CreateProcessAsUser 创建进程,但没有控制台
- 子进程 c++ 的 Windows 控制台信号处理
- C++ Windows CreateChildProcess - 隐藏/不显示子进程的控制台窗口
- 控制台输出到子进程
- 关闭Qt控制台应用程序会终止exec()调用中的进程,并且无法从main()扩展到范围
- 这是否可以挂接子进程发送到 Windows 控制台的消息
- 可以放置一个钩子来捕获由子进程发送到控制台的消息
- Windows -- 继承子进程中的控制台文件句柄
- 在远程进程中隐藏控制台窗口
- 如何获取绑定到我正在运行的控制台窗口的进程列表,这些进程也可以在 Windows 2000 中工作?
- (c++, Windows)生成没有控制台窗口的子进程(使用CreateProcess)
- 读取分离进程的控制台输出
- 如何启动控制台进程
- 用新的控制台窗口创建进程,但覆盖一些std i/o句柄
- 如何用c++或C语言将控制台的内容写入文件,多个进程/exe可以写入控制台