7 posts
Posted 06 April 2014 - 12:45 AM
Hey guys, I had the brilliant idea to "edit startup" so it hosts gps requests immediately. I've tried various things and have only learned how it's not done.
parameters = {"host", "-302", "61", "234"}
os.run({}, "/rom/programs/gps", parameters)
This is the closest I've gotten, but it just outputs the Usage description as if I'd only typed "gps" at the command prompt.
Any thoughts what I'm not doing right here?
995 posts
Location
Canada
Posted 06 April 2014 - 04:40 AM
You should use shell.run() if you don't understand os.run(), so do this:
shell.run("gps host -302 61 234")
1220 posts
Location
Earth orbit
Posted 06 April 2014 - 09:10 AM
awsmazinggenius' solution is probably the most direct. On the off chance that you want to make use of the 'parameters' variable you could try something like this…
local parameters = {"-302", "61", "234"}
local sRun = "gps host " .. parameters[1] .. " " .. parameters[2] .. " " .. parameters[3]
shell.run(sRun)
Edited on 06 April 2014 - 07:17 AM
7 posts
Posted 06 April 2014 - 09:13 AM
That's got it, thanks genius. Still not sure what os.run does, but that's been demoted to research-'cause-I'm-bored. :)/>
And thank you Dog for giving me a different approach to consider.
7083 posts
Location
Tasmania (AU)
Posted 06 April 2014 - 09:17 AM
On the off chance that you want to make use of the 'parameters' variable you could try something like this…
An easier way involves use of "unpack", which does pretty much the same thing but is rather more dynamic:
local parameters = {"-302", "61", "234"}
shell.run( "gps host", unpack(parameters) )
The end result is akin to writing:
shell.run( "gps host", "-302", "61", "234" )
7508 posts
Location
Australia
Posted 06 April 2014 - 09:23 AM
Still not sure what os.run does, but that's been demoted to research-'cause-I'm-bored. :)/>
os.run is a lower level version of
shell.run, well actually
shell.run uses
os.run.
when you use
shell.run the program runs just like if you were to run it from the terminal, this means it has access to the Shell API as well as all other APIs in the global table.
however when
os.run is used the program only gets access to the global table and anything else you provide in the first 'environment variables' table.
basically here is the simplest implementation of
shell.run, you'll notice that it uses
os.run and gives the programs the Shell API via the first argument.
function shell.run( programPath, ... )
return os.run( {['shell'] = shell}, programPath, ... )
end
obviously there's a lot more code in the real implementation, but this was a 'simplest form' example
Edited on 06 April 2014 - 07:23 AM
7 posts
Posted 08 April 2014 - 12:07 AM
Thank you very much theoriginalbit for your clarification of the different .run commands. I appreciate it.