mirror of
https://gitlab.com/Syping/luaengineapp.git
synced 2024-12-22 11:55:29 +01:00
improve executeProcess
This commit is contained in:
parent
7773d84176
commit
1ddf257a41
1 changed files with 35 additions and 11 deletions
|
@ -35,25 +35,49 @@ void LuaEngineOS::pushClass(LuaEngine *luaEngine)
|
|||
int LuaEngineOS::executeProcess(lua_State *L_p)
|
||||
{
|
||||
if (getArgumentCount(L_p) >= 1) {
|
||||
QProcess *process = new QProcess;
|
||||
int processReturn = 0;
|
||||
bool runInBackground = false;
|
||||
bool processExecuted = false;
|
||||
if (getArgumentCount(L_p) >= 2) {
|
||||
QVariantList arguments = getArguments(L_p);
|
||||
QVariant lastArgument = arguments.last();
|
||||
if (lastArgument.type() == QVariant::Bool) {
|
||||
runInBackground = lastArgument.toBool();
|
||||
arguments.removeLast();
|
||||
}
|
||||
if (arguments.length() >= 2) {
|
||||
QStringList processArguments;
|
||||
QString processPath = arguments.first().toString();
|
||||
arguments.removeFirst();
|
||||
for (const QVariant &argument : arguments) {
|
||||
processArguments << argument.toString();
|
||||
}
|
||||
process->start(processPath, processArguments, QProcess::ReadOnly);
|
||||
if (runInBackground) {
|
||||
processExecuted = QProcess::startDetached(processPath, processArguments);
|
||||
}
|
||||
else {
|
||||
process->start(getVariant(L_p, 1).toString(), QProcess::ReadOnly);
|
||||
processReturn = QProcess::execute(processPath, processArguments);
|
||||
}
|
||||
QObject::connect(process, SIGNAL(finished(int)), process, SLOT(deleteLater()));
|
||||
pushVariant(L_p, true);
|
||||
}
|
||||
else {
|
||||
if (runInBackground) {
|
||||
processExecuted = QProcess::startDetached(arguments.first().toString());
|
||||
}
|
||||
else {
|
||||
processReturn = QProcess::execute(arguments.first().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
processReturn = QProcess::execute(getVariant(L_p, 1).toString());
|
||||
}
|
||||
if (runInBackground && !processExecuted) {
|
||||
processReturn = -2;
|
||||
}
|
||||
pushVariant(L_p, processReturn);
|
||||
return 1;
|
||||
}
|
||||
pushVariant(L_p, false);
|
||||
pushVariant(L_p, -2);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue