20 posts
Posted 11 November 2012 - 11:23 AM
I'm trying to test if a file can be launched as a program.
I have been using shell.run and see if it returns true or false, my problem is that this command prints "No such program" (if the file can not be launched) to the console and this breaks my layout.
So what do I do?
1054 posts
Posted 11 November 2012 - 11:29 AM
local programName = 'testProgram'
local succes = pcall( shell.run(programName) )
pcall returns true when the function inside succeeds (and as other parameters the results from the function call). It suppresses error messages.
2447 posts
Posted 11 November 2012 - 11:45 AM
I'm trying to test if a file can be launched as a program.
I have been using shell.run and see if it returns true or false, my problem is that this command prints "No such program" (if the file can not be launched) to the console and this breaks my layout.
So what do I do?
Check if shell.resolve works first.
59 posts
Location
Washington, United States
Posted 11 November 2012 - 12:43 PM
The error means that the path you gave it isn't a valid program path. Make sure that the file path you gave it is valid.
715 posts
Posted 11 November 2012 - 01:21 PM
local programName = 'testProgram'
local succes = pcall( shell.run(programName) )
pcall returns true when the function inside succeeds (and as other parameters the results from the function call). It suppresses error messages.
You have to pass the function reference with its arguments as separate arguments to pcall().
That is, the correct call would be:
pcall( shell.run, programName )
Edit: Changed the wording a bit to prevent possible confusion (hopefully)^^.
Edited on 11 November 2012 - 12:23 PM
1054 posts
Posted 11 November 2012 - 01:27 PM
local programName = 'testProgram'
local succes = pcall( shell.run(programName) )
pcall returns true when the function inside succeeds (and as other parameters the results from the function call). It suppresses error messages.
You have to pass the function reference with its arguments as separate arguments to pcall().
That is, the correct call would be:
pcall( shell.run, programName )
Edit: Changed the wording a bit to prevent possible confusion (hopefully)^^.
Oh yea, thanks. Totally didn't see that. :unsure:/>/>