Running .exe file using QProcess creates hundreds of the same processes

528 views Asked by At

I have a problem running phantomjs.exe binary in my QProcess class. Consider this code:

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

When I start the app main process loads up and nothing happens after that, just hundreds of other phantomjs.exe are created (checking it in TaskManager) as well as conhost.exe processes.

I tried other exe files, like notepad.exe, and it works just fine. Notepad window appears.

Did you encounter this problem?

2

There are 2 answers

0
Maxim Makhun On BEST ANSWER

After checking I found that there is a problem with QProcess. I used SHELLEXECUTEINFO instead. This code works for me well. No recursive calls of phantomjs.exe here:

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);
1
phyatt On

Do you call phantom.exit() in your test script?

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

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

Hope that helps.