This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
zwap1233's profile picture

[Lua][Question] How does os.run() work?

Started by zwap1233, 02 October 2012 - 11:30 AM
zwap1233 #1
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?
Mtdj2 #2
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…)
Orwell #3
Posted 02 October 2012 - 01:55 PM
The syntax of os.run is found here:
http://www.computercraft.info/wiki/index.php?title=Os.run

You can find a bit of information on Environments here:
http://www.lua.org/pil/14.html

I 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.
Doyle3694 #4
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
zwap1233 #5
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.
zwap1233 #6
Posted 02 October 2012 - 02:02 PM
The syntax of os.run is found here:
http://www.computerc...hp?title=Os.run

You can find a bit of information on Environments here:
http://www.lua.org/pil/14.html

I 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
Lyqyd #7
Posted 02 October 2012 - 02:10 PM
Not with the quotes around test.
zwap1233 #8
Posted 02 October 2012 - 02:11 PM
Not with the quotes around test.

so if i use env = {['textutils'] = test}
it will work?
Orwell #9
Posted 02 October 2012 - 02:22 PM
Not with the quotes around test.

so if i use env = {['textutils'] = test}
it will work?
Yes.
zwap1233 #10
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!
zwap1233 #11
Posted 02 October 2012 - 02:43 PM
it works thanks