19 posts
Posted 02 October 2012 - 01:30 PM
like the title says: 'How does os.run() work?'
i understand that is runs the file in the second argument.
but how do i use the first argument and what does it do?
62 posts
Location
Behind you
Posted 02 October 2012 - 01:42 PM
Well, unless you are going to use the first thing (environment), I'd recomment you to use
shell.run( program, arguments )Hope I helped.
Edit: Enviroment is where the variables are stored. (Or that is what I think…)
1054 posts
Posted 02 October 2012 - 01:55 PM
The syntax of os.run is found here:
http://www.computercraft.info/wiki/index.php?title=Os.runYou can find a bit of information on Environments here:
http://www.lua.org/pil/14.htmlI quickly made some code illustrating the use:
test1
env = {}
env.a = function() return 42 end
os.run(env, 'test2')
test2
print(a())
Basically, the environment is a (meta)table that stores all global variables and functions (like fs, rednet, print(), …).
So basically this allows you to run programs with adapted global vars/functions.
818 posts
Posted 02 October 2012 - 01:56 PM
enviroment is where is where it's ran. and enviroment works with shell.run. so shell.run("Monitor", "right", HelloWorld) would run HellowWorld on the right monitor
EDIT:Ninja'd
19 posts
Posted 02 October 2012 - 01:56 PM
Well, unless you are going to use the first thing (environment), I'd recomment you to use
shell.run( program, arguments )Hope I helped.
Edit: Enviroment is where the variables are stored. (Or that is what I think…)
i know what shell.run() does but the environment option may give me a solution to a problem i have.
i want to run a program in a folder but the program must not go out that folder i hoped the environment argument would allow me to manipulate the program by making the program think he is using the normal apis but excutly he running my api that edits the path and than excutes the normal api whit the modifed path, i saw something like that in the shell. (os.run({['shell'] = shell}) , _sPath) but i'm not sure what it is doing and how i could use it myself.
19 posts
Posted 02 October 2012 - 02:02 PM
The syntax of os.run is found here:
http://www.computerc...hp?title=Os.runYou can find a bit of information on Environments here:
http://www.lua.org/pil/14.htmlI quickly made some code illustrating the use:
test1
env = {}
env.a = function() return 42 end
os.run(env, 'test2')
test2
print(a())
Basically, the environment is a (meta)table that stores all global variables and functions (like fs, rednet, print(), …).
So basically this allows you to run programs with adapted global vars/functions.
if i make a api and i call it test whit a method SlowPrint
and i run a program whit os.run(env,'program')
and local env = {['textutils'] = 'test'}
would the program run my SlowPrint method everytime when he calls 'textutils.SlowPrint()'?
and thanks for the links
8543 posts
Posted 02 October 2012 - 02:10 PM
Not with the quotes around test.
19 posts
Posted 02 October 2012 - 02:11 PM
Not with the quotes around test.
so if i use env = {['textutils'] = test}
it will work?
1054 posts
Posted 02 October 2012 - 02:22 PM
Not with the quotes around test.
so if i use env = {['textutils'] = test}
it will work?
Yes.
19 posts
Posted 02 October 2012 - 02:24 PM
Not with the quotes around test.
so if i use env = {['textutils'] = test}
it will work?
Yes.
thanks :(/>/> going to test it now!
19 posts
Posted 02 October 2012 - 02:43 PM
it works thanks