mirror of
https://gitlab.com/Syping/luaengineapp.git
synced 2024-11-04 21:16:56 +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);
|
||||
QStringList processArguments;
|
||||
QString processPath = arguments.first().toString();
|
||||
arguments.removeFirst();
|
||||
for (const QVariant &argument : arguments) {
|
||||
processArguments << argument.toString();
|
||||
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();
|
||||
}
|
||||
if (runInBackground) {
|
||||
processExecuted = QProcess::startDetached(processPath, processArguments);
|
||||
}
|
||||
else {
|
||||
processReturn = QProcess::execute(processPath, processArguments);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (runInBackground) {
|
||||
processExecuted = QProcess::startDetached(arguments.first().toString());
|
||||
}
|
||||
else {
|
||||
processReturn = QProcess::execute(arguments.first().toString());
|
||||
}
|
||||
}
|
||||
process->start(processPath, processArguments, QProcess::ReadOnly);
|
||||
}
|
||||
else {
|
||||
process->start(getVariant(L_p, 1).toString(), QProcess::ReadOnly);
|
||||
processReturn = QProcess::execute(getVariant(L_p, 1).toString());
|
||||
}
|
||||
QObject::connect(process, SIGNAL(finished(int)), process, SLOT(deleteLater()));
|
||||
pushVariant(L_p, true);
|
||||
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