使用QProcess运行.exe文件会创建数百个相同的进程

时间:2013-12-05 15:08:47

标签: qt phantomjs qprocess

我在QProcess类中运行phantomjs.exe二进制文件时遇到问题。请考虑以下代码:

QString program = "phantomjs.exe";
QProcess *process = new QProcess(this);
process->start(program, QStringList() << "test.js");

当我启动应用程序主进程加载并且之后没有任何反应时,只创建了数百个其他phantomjs.exe(在TaskManager中检查它)以及conhost.exe进程。

我尝试了其他exe文件,比如notepad.exe,它运行得很好。出现记事本窗口。

你遇到过这个问题吗?

2 个答案:

答案 0 :(得分:2)

您是否在测试脚本中调用了phantom.exit()

https://github.com/ariya/phantomjs/wiki/Quick-Start

console.log('Hello, world!');
phantom.exit();

希望有所帮助。

答案 1 :(得分:0)

检查后发现QProcess存在问题。我改用了SHELLEXECUTEINFO。这段代码对我很有用。这里没有pha​​ntomjs.exe的递归调用:

SHELLEXECUTEINFO shExecInfo;
shExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);

shExecInfo.fMask = NULL;
shExecInfo.hwnd = NULL;
shExecInfo.lpVerb = L"runas";
shExecInfo.lpFile = L"phantomjs.exe";
shExecInfo.lpParameters = L"test.js";
shExecInfo.lpDirectory = NULL;
shExecInfo.nShow = SW_NORMAL;
shExecInfo.hInstApp = NULL;

ShellExecuteEx(&shExecInfo);
相关问题