Skip to content

Instantly share code, notes, and snippets.

@Miqueas
Last active March 13, 2021 04:54
Show Gist options
  • Save Miqueas/212e1a75122c166c2e3a13b4a0d1f03c to your computer and use it in GitHub Desktop.
Save Miqueas/212e1a75122c166c2e3a13b4a0d1f03c to your computer and use it in GitHub Desktop.
[Lua + Gio] Subprocess
local lgi = require("lgi")
local Gio = lgi.require("Gio", "2.0")
--[[ Arguments:
1 (table): The first element is the commandline process name, the rest are commandline arguments
2 (table): A list of Gio.SubprocessFlags
]]
local sub = Gio.Subprocess.new(
{ "echo", "Hello", "world!" },
{ Gio.SubprocessFlags.NONE, Gio.SubprocessFlags.STDOUT_PIPE }
)
-- Synchronously wait for the subprocess to terminate
if sub:wait() then
local data = Gio.DataInputStream.new(sub:get_stdout_pipe())
local line = data:read_line()
while line ~= nil do
print(line .. "\n")
line = data:read_line()
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment