I tried if shell.getRunningProgram() then and if shell.getRunningProgram() == true then but neither seem want to work correclty.
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
reboot if program isn't running or crashes?
Started by subzero22, 24 September 2016 - 11:36 PMPosted 25 September 2016 - 01:36 AM
is it possible to make a computer reboot with shell.getRunningProgram("program name") if it stops or crashes?
I tried if shell.getRunningProgram() then and if shell.getRunningProgram() == true then but neither seem want to work correclty.
I tried if shell.getRunningProgram() then and if shell.getRunningProgram() == true then but neither seem want to work correclty.
Posted 25 September 2016 - 01:42 AM
Well, if your program isn't running, and that statement is in your program, it isn't going to run either, is it? Could you clarify your intent?
Posted 25 September 2016 - 04:43 AM
ah ok sorry. Using an advanced computer. The main program will be running. Then I have another program trying to check if the one program is running or not. If it's not then I'm trying to get it to restart the computer to get it to run again I'm having trouble with the if program is running check or is it even possible to do? It's mainly cause I'm playing on a server and when the chunks reload the program crashes at times cause I'm using wired modems to a few places around my base to control. it. But cause of that when I head back to my base the program crashes and I want another program to see if it stopped running to restart it.
Posted 25 September 2016 - 07:34 AM
broke,error = pcall(loadfile(name))
if broke and error ~= "terminated" then
print("Eewor: " .. error)
sleep(3)
os.reboot()
end
if broke and error ~= "terminated" then
print("Eewor: " .. error)
sleep(3)
os.reboot()
end
Posted 25 September 2016 - 01:10 PM
Well, "if not broke" maybe… bearing in mind that pcall returns whether the call completed successfully or not!
In any case, it'd be somewhat simpler to just put this in your startup file:
In any case, it'd be somewhat simpler to just put this in your startup file:
while true do shell.run("targetScriptToRepeat") end
Edited on 25 September 2016 - 11:11 AM
Posted 25 September 2016 - 03:57 PM
Could you not do this?
EDIT: BB's solution avoids the reboot and is the better solution.
shell.run("program")
os.reboot()
EDIT: BB's solution avoids the reboot and is the better solution.
Edited on 25 September 2016 - 02:25 PM
Posted 26 September 2016 - 08:02 AM
Well, "if not broke" maybe… bearing in mind that pcall returns whether the call completed successfully or not!
In any case, it'd be somewhat simpler to just put this in your startup file:while true do shell.run("targetScriptToRepeat") end
what if you want to terminate it d:
Posted 26 September 2016 - 08:31 AM
Such functionality wasn't requested, but if you were using my loop, you'd indeed need something like an external boot disk to break out of it.