Jump to content

how to reopen a program if its not running/it crashes


Recommended Posts

i want to be able to keep a program running so that when it crashes or closes the script can reopen it this is what i have been able to write

any explaination on what im doing wrong or what i can do better is helpful

ps i am kinda new to this :)

what i wrote:

if ProcessExists("C:\WINDOWS\system32\cmd.exe") Then
    Sleep(1000)
Else
    Run(@ScriptDir & "\start.bat")
    EndIf

extra info:

i run a bat file that opens a cmd terminal, when i close it or it crashes it doesnt reopen, this is my issue

 

Link to post
Share on other sites
  • Developers
1 hour ago, hackjet said:

"C:\WINDOWS\system32\cmd.exe"

This is not  a process name you will find in the TaskManager!
Testing on cmd.exe is not going to work well in case other tasks with the same name exists.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to post
Share on other sites

Welcome to the forum @hackjet

So, what is a .bat file !. A batch file is basically a list of commands in a text file that the command interpreter ( cmd.exe ) runs, because the extension of the file is named bat ( or cmd ).
Since you show no experience with all this, you can share what is that you'd like to get done and we would give you a most excellent solution ( usually ). :) 

Link to post
Share on other sites

Try it with the function "_SingleScript ()"
Here's an example:

#include "_SingleScript.au3" ; http : / / www.autoitscript.com / forum / index.php ? showtopic = 178681
_SingleScript(1)              ; pause, if predessesor running.
ShellExecute(@ScriptFullPath) ; submit successor.
If 2 <> RunWait(@ComSpec & " /c " & @ScriptDir & "\start.bat") Then Exit
_SingleScript(0)     ; break start.bat loop if bat answer was "y"

and here the corresponding "Start.bat"

@echo off
echo.
echo #############################
echo #                           #
echo #  Start.bat is now active  #
echo #                           #
echo #############################
echo.

echo Insert your working code here

echo.
choice /T 9 /C NY /D N /M "Terminate Start.bat loop    "

 

Edited by Exit
changed the "choice" behavior to restart after timeout

App: Au3toCmd              UDF: _SingleScript()                             

Link to post
Share on other sites
1 hour ago, Jos said:

This is not  a process name you will find in the TaskManager!
Testing on cmd.exe is not going to work well in case other tasks with the same name exists.

Jos

i didnt know that, thanks for the info on that

Link to post
Share on other sites
1 hour ago, argumentum said:

Welcome to the forum @hackjet

So, what is a .bat file !. A batch file is basically a list of commands in a text file that the command interpreter ( cmd.exe ) runs, because the extension of the file is named bat ( or cmd ).
Since you show no experience with all this, you can share what is that you'd like to get done and we would give you a most excellent solution ( usually ). :) 

thanks for the reply im trying to learn all the little details since not alot of tutorials on youtube exist for autoit

Link to post
Share on other sites
3 minutes ago, Exit said:

Try it with the function "_SingleScript ()"
Here's an example:

#include "_SingleScript.au3"  ; http://www.autoitscript.com/forum/index.php?showtopic=178681
_SingleScript(1)              ; pause, if predessesor is running.
ShellExecute(@ScriptFullPath) ; submit successor.
If 1 <> RunWait(@ComSpec & " /c " & @ScriptDir & "\start.bat") Then Exit
_SingleScript(0)              ; terminate start.bat loop if start.bat answer was "J"

and here the corresponding "Start.bat"

@echo off
echo.
echo #############################
echo #                           #
echo #  Start.bat is now active  #
echo #                           #
echo #############################
echo.

rem Insert your working code here

echo.
echo Terminate Start.bat loop?
choice

 

thanks for the help i will try this and learn from it piece by piece 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...