Reputation: 869
I am trying to activate some Lua lines only if the output of pgrep -x foo
is empty. I have tried the following:
if os.execute("pgrep -x foo") then
-- My lines here
end
However, this doesn't seem to be the correct solution, even syntactically OK.
Upvotes: 1
Views: 578
Reputation: 23727
local result = os.execute("pgrep -x foo")
if result ~= true and result ~= 0 then
-- My lines here (no such process)
end
Upvotes: 3
Reputation: 47169
Maybe try checking for nil
:
if os.execute('pgrep -x foo') == nil then
print('empty')
end
If you don't want the match to be "exact" then remove the -x
option.
Upvotes: 1