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

[QUESTION] Detecting program exit?

Started by Mackan90096, 14 March 2013 - 10:26 PM
Mackan90096 #1
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
theoriginalbit #2
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)
Mackan90096 #3
Posted 14 March 2013 - 11:46 PM
In a bit easier to understand please?
theoriginalbit #4
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)
Mackan90096 #5
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..
theoriginalbit #6
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()
Mackan90096 #7
Posted 15 March 2013 - 12:01 AM
ah. ok thanks!
theoriginalbit #8
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.
Mackan90096 #9
Posted 15 March 2013 - 12:24 AM
ah
Bubba #10
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.
theoriginalbit #11
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.
eleure #12
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')