Skip to content

Instantly share code, notes, and snippets.

@erikLundstedt
Forked from dukeofgaming/os.capture
Last active September 30, 2022 12:54

Revisions

  1. erikLundstedt revised this gist Sep 30, 2022. 1 changed file with 9 additions and 9 deletions.
    18 changes: 9 additions & 9 deletions shell.lua
    Original file line number Diff line number Diff line change
    @@ -7,21 +7,21 @@ local shell={}
    function shell.capture(cmd)
    local handle = assert(io.popen(cmd, 'r'))
    local output = assert(handle:read('*a'))

    handle:close()

    local raw=output
    local raw=output
    output = string.gsub(
    string.gsub(
    string.gsub(output, '^%s+', ''),
    '%s+$',
    string.gsub(output, '^%s+', ''),
    '%s+$',
    ''
    ),
    ),
    '[\n\r]+',
    ' '
    )

    return {"out" output "raw" raw}
    local o={}
    o["out"] = output
    o["raw"] = raw
    return o
    end

    shell
    return shell
  2. erikLundstedt revised this gist Sep 30, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion shell.lua
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@ function shell.capture(cmd)
    ' '
    )

    return {"out" output "raw" raw)
    return {"out" output "raw" raw}
    end

    shell
  3. erikLundstedt revised this gist Sep 30, 2022. 1 changed file with 3 additions and 6 deletions.
    9 changes: 3 additions & 6 deletions shell.lua
    Original file line number Diff line number Diff line change
    @@ -4,16 +4,13 @@
    local shell={}


    function shell.capture(cmd, raw)
    function shell.capture(cmd)
    local handle = assert(io.popen(cmd, 'r'))
    local output = assert(handle:read('*a'))

    handle:close()

    if raw then
    return output
    end

    local raw=output
    output = string.gsub(
    string.gsub(
    string.gsub(output, '^%s+', ''),
    @@ -24,7 +21,7 @@ function shell.capture(cmd, raw)
    ' '
    )

    return output
    return {"out" output "raw" raw)
    end

    shell
  4. erikLundstedt renamed this gist Sep 30, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. erikLundstedt revised this gist Sep 30, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion os.capture
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    ---
    -- Function to retrieve console output
    --
    lcoal shell={}
    local shell={}


    function shell.capture(cmd, raw)
  6. erikLundstedt revised this gist Sep 30, 2022. 1 changed file with 8 additions and 3 deletions.
    11 changes: 8 additions & 3 deletions os.capture
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,10 @@
    ---
    -- Function to retrieve console output
    --
    function os.capture(cmd, raw)
    --
    lcoal shell={}


    function shell.capture(cmd, raw)
    local handle = assert(io.popen(cmd, 'r'))
    local output = assert(handle:read('*a'))

    @@ -22,4 +25,6 @@ function os.capture(cmd, raw)
    )

    return output
    end
    end

    shell
  7. @dukeofgaming dukeofgaming created this gist Jun 9, 2014.
    25 changes: 25 additions & 0 deletions os.capture
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    ---
    -- Function to retrieve console output
    --
    function os.capture(cmd, raw)
    local handle = assert(io.popen(cmd, 'r'))
    local output = assert(handle:read('*a'))

    handle:close()

    if raw then
    return output
    end

    output = string.gsub(
    string.gsub(
    string.gsub(output, '^%s+', ''),
    '%s+$',
    ''
    ),
    '[\n\r]+',
    ' '
    )

    return output
    end