Lua: Add function that returns the output of a process

Change-Id: I6863926a4da90adc89d96d47da1542c886b44040
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
David Schulz
2024-05-27 06:27:30 +02:00
parent 36f2a21f2d
commit d8a582d813
2 changed files with 17 additions and 0 deletions

View File

@@ -29,11 +29,22 @@ void addProcessModule()
p->setEnvironment(Environment::systemEnvironment());
QObject::connect(p, &Process::done, guard, [p, cb]() { cb(p->exitCode()); });
};
process["commandOutput_cb"] =
[guard
= pluginSpec->connectionGuard.get()](const QString &cmdline, const sol::function &cb) {
Process *p = new Process;
p->setCommand(CommandLine::fromUserInput((cmdline)));
p->setEnvironment(Environment::systemEnvironment());
QObject::connect(p, &Process::done, guard, [p, cb]() { cb(p->allOutput()); });
p->start();
};
process["runInTerminal"] = wrap(process["runInTerminal_cb"]);
process["commandOutput"] = wrap(process["commandOutput_cb"]);
return process;
});

View File

@@ -8,4 +8,10 @@ local process = {}
---@return number The exit code of the command
function process.runInTerminal(cmd) end
---@async
---Runs a command and returns the output!
---@param cmd string The command to run
---@return string The output of the command
function process.commandOutput(cmd) end
return process