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)
|
int LuaEngineOS::executeProcess(lua_State *L_p)
|
||||||
{
|
{
|
||||||
if (getArgumentCount(L_p) >= 1) {
|
if (getArgumentCount(L_p) >= 1) {
|
||||||
QProcess *process = new QProcess;
|
int processReturn = 0;
|
||||||
|
bool runInBackground = false;
|
||||||
|
bool processExecuted = false;
|
||||||
if (getArgumentCount(L_p) >= 2) {
|
if (getArgumentCount(L_p) >= 2) {
|
||||||
QVariantList arguments = getArguments(L_p);
|
QVariantList arguments = getArguments(L_p);
|
||||||
QStringList processArguments;
|
QVariant lastArgument = arguments.last();
|
||||||
QString processPath = arguments.first().toString();
|
if (lastArgument.type() == QVariant::Bool) {
|
||||||
arguments.removeFirst();
|
runInBackground = lastArgument.toBool();
|
||||||
for (const QVariant &argument : arguments) {
|
arguments.removeLast();
|
||||||
processArguments << argument.toString();
|
}
|
||||||
|
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 {
|
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()));
|
if (runInBackground && !processExecuted) {
|
||||||
pushVariant(L_p, true);
|
processReturn = -2;
|
||||||
|
}
|
||||||
|
pushVariant(L_p, processReturn);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
pushVariant(L_p, false);
|
pushVariant(L_p, -2);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue