239 posts
Location
Macintosh HD/Users/LoganDark
Posted 18 June 2016 - 01:50 AM
I want to use shell.run to run a program that may not exist, and I have my own error message that I want to display instead of "No such program". Is that possible?
Edited on 18 June 2016 - 12:00 AM
7508 posts
Location
Australia
Posted 18 June 2016 - 01:55 AM
Error handling and Exceptions over at the Lua manual will point you in the direction of
pcall.
It would go a little like this
local ok, err = pcall(function() shell.run("program") end)
if not ok then
print("No program")
end
Edited on 17 June 2016 - 11:55 PM
239 posts
Location
Macintosh HD/Users/LoganDark
Posted 18 June 2016 - 01:56 AM
Error handling and Exceptions over at the Lua manual will point you in the direction of
pcall.
It would go a little like this
local ok, err = pcall(function() shell.run("program") end)
if not ok then
print("No program")
end
Okay, thanks. I forgot about pcall.
7083 posts
Location
Tasmania (AU)
Posted 18 June 2016 - 02:16 AM
shell.run() doesn't actually error if the targeted file doesn't exist. You'd be better off using fs.exists() to check before attempting to run in the first place.
239 posts
Location
Macintosh HD/Users/LoganDark
Posted 18 June 2016 - 02:18 AM
shell.run() doesn't actually error if the targeted file doesn't exist. You'd be better off using fs.exists() to check before attempting to run in the first place.
Oh, okay.
Edit: So
fs.combine shell.dir() and what to run?
Edit 2: I guess that's a yes
Edited on 18 June 2016 - 12:25 AM