如何启动控制台进程
我正在从我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试 system() 函数;它将像从 Windows cmd 运行一样运行命令
try the system() function; it will run the commands as if run from windows cmd
首先 控制台不会在 Windows 中使用 QProcess 打开
所以你应该使用 readAllStandardOutput() 或 readChannel() 或其他提供的函数之一读取进程标准输出。我不知道 vm.exe 做了什么,但假设路径正确并且 procError( int ) 从未被调用......该进程正在正确运行并完成。
如果要使用Readyread()信号,需要设置读取通道。但我建议使用 readyReadStandardOutput() 信号代替。
Firstly The console won't open with QProcess in windows
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.