Last active
March 13, 2021 04:54
-
-
Save Miqueas/212e1a75122c166c2e3a13b4a0d1f03c to your computer and use it in GitHub Desktop.
[Lua + Gio] Subprocess
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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