695 posts
Location
In my basement.
Posted 14 March 2013 - 11:26 PM
Hi! Can i make a script where it detects if a shell program is exited, and then run a function from that? (In this case "edit")
And if so, how?
Thanks for help //Mackan90096
7508 posts
Location
Australia
Posted 14 March 2013 - 11:33 PM
if you have used shell.run your program will not continue running until the other program is finished (unless you're using coroutines)
695 posts
Location
In my basement.
Posted 14 March 2013 - 11:46 PM
In a bit easier to understand please?
7508 posts
Location
Australia
Posted 14 March 2013 - 11:49 PM
an example
print("Your program running")
shell.run("Some Program") -- waits here until program is finished
print("Program finished running")
the only time this does not work when it is like this
local function one()
print("starting program")
shell.run('someProgram')
print("program finished") -- this doesnt print until its finished
end
local function two()
print("this always will print even when the other is running")
end
parallel.waitForAll(one,two)
695 posts
Location
In my basement.
Posted 14 March 2013 - 11:51 PM
I dont really understand…
I want to first run the "edit" program and when the user have saved and exited the program start a function from that..
7508 posts
Location
Australia
Posted 14 March 2013 - 11:57 PM
ok lets put it black and white for you (even though its going to be the same code example, just with maybe things you will hopefully understand?)
local function derpyDerp()
print("derpy derp")
end
print("Starting up edit")
sleep(1)
shell.run("edit some/file")
derpyDerp()
695 posts
Location
In my basement.
Posted 15 March 2013 - 12:01 AM
ah. ok thanks!
7508 posts
Location
Australia
Posted 15 March 2013 - 12:05 AM
just so you know. print is a function! thats why those 2 code examples are exactly the same.
695 posts
Location
In my basement.
Posted 15 March 2013 - 12:24 AM
ah
1190 posts
Location
RHIT
Posted 15 March 2013 - 03:17 AM
I may be wrong about this, but does not shell.run take the program name and then the arguments separately?
For example, it should be shell.run("/rom/programs/edit", "editThisProgram"). I can't test right now, but according to the wiki that is the correct usage. Of course, it may be that it works both ways.
7508 posts
Location
Australia
Posted 15 March 2013 - 03:24 AM
It used to be that they had to be separate arguments. but i think it was 1.4 they added in the ability to supply a single string. I thought the same too when someone first did it.
42 posts
Posted 15 March 2013 - 05:41 AM
i don't know anything about previous versions, but here:
function shell.run( ... )
return runLine( table.concat( { ... }, " " ) )
end
shell.run('edit some/file')
shell.run('edit', 'some/file')
each would be 'edit some/file' once passed to runLine.
edit:
local function foo(...)
print(table.concat( {...}, " "))
end
foo('edit', 'some/file')
foo('edit some/file')