forflo / shepi

Tiny EDSL for shell pipes in lua
13 stars 0 forks source link

get return code #1

Open vredesbyyrd opened 5 years ago

vredesbyyrd commented 5 years ago

EDIT: After running into a situation where I would like to obtain a commands return code, again, I am restating and reopening this issue.

When I want something more than bash for shell scripting, I much prefer lua + shepi piping implementation over say python + subprocess. The one thing that would make it more complete imo is a way to retrieve the last commands return code in addition to its output.

With popen:

local file = io.popen('rofi -dmenu -kb-custom-1 ctrl+0')
local output = file:read('*all')
-- This will get a table with some return stuff
-- rc[1] will be true, false or nil
-- rc[3] will be the signal
local rc = {file:close()}
print(rc[3])

This answer on stackoverflow uses lua-posix and allows for grabbing the exit status.

Could something similar be implemented with shepi and its different datatypes, command, pipe, fork, fun?

EDIT:

Or exit status of command, pipe, i'm not sure fork, fun are relevant here.

forflo commented 4 years ago

Hey,

thanks for your interest in my code! I will look into it!