Jump to content




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


  • You cannot reply to this topic
10 replies to this topic

#1 zwap1233

  • Members
  • 37 posts

Posted 02 October 2012 - 12: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?

#2 Mtdj2

  • Members
  • 66 posts
  • LocationBehind you

Posted 02 October 2012 - 12: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...)

#3 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 02 October 2012 - 12:55 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.

#4 Doyle3694

  • Members
  • 815 posts

Posted 02 October 2012 - 12: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

#5 zwap1233

  • Members
  • 37 posts

Posted 02 October 2012 - 12:56 PM

View PostMtdj2, on 02 October 2012 - 12:42 PM, said:

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.

#6 zwap1233

  • Members
  • 37 posts

Posted 02 October 2012 - 01:02 PM

View PostOrwell, on 02 October 2012 - 12:55 PM, said:

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

#7 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 02 October 2012 - 01:10 PM

Not with the quotes around test.

#8 zwap1233

  • Members
  • 37 posts

Posted 02 October 2012 - 01:11 PM

View PostLyqyd, on 02 October 2012 - 01:10 PM, said:

Not with the quotes around test.

so if i use env = {['textutils'] = test}
it will work?

#9 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 02 October 2012 - 01:22 PM

View Postzwap1233, on 02 October 2012 - 01:11 PM, said:

View PostLyqyd, on 02 October 2012 - 01:10 PM, said:

Not with the quotes around test.

so if i use env = {['textutils'] = test}
it will work?
Yes.

#10 zwap1233

  • Members
  • 37 posts

Posted 02 October 2012 - 01:24 PM

View PostOrwell, on 02 October 2012 - 01:22 PM, said:

View Postzwap1233, on 02 October 2012 - 01:11 PM, said:

View PostLyqyd, on 02 October 2012 - 01:10 PM, said:

Not with the quotes around test.

so if i use env = {['textutils'] = test}
it will work?
Yes.

thanks :(/> going to test it now!

#11 zwap1233

  • Members
  • 37 posts

Posted 02 October 2012 - 01:43 PM

it works thanks





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users