forked from qt-creator/qt-creator
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:
@@ -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;
|
||||
});
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user