Batch file – looking for one-liners?

Hi everyone

please give a quick tip (one-liner if possible).

  • A program runs on a server under msaccess – all day, 24/7
  • There are reasons why the process might crash. One example is when the server reboots for updates or when the VPN fails to maintain the connection (rare, but it does happen).
  • I would like to restart the program – everything is already prepared and working.

What single or multi-line command can I use to check (e.g. once a day in the timer – would work) whether the thing is running.

I haven't done any Windows batch work in a long time. On Linux, I would simply do:

ps -ef | grep msaccess

RC=$?

and then restart the program depending on the RC / return code

This must work under Windows too.

(1 votes)
Loading...

Similar Posts

Subscribe
Notify of
4 Answers
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Xandros0506
7 months ago
tasklist | find /i "msaccess.exe" || "c:\Program Files\MSOfficeXX.xx\msaccess.exe"

You will be able to and must adapt the path to the installation of Access.

PowerShell would be more up-to-date. But if you want to use the outdated can shell….

Erzesel
7 months ago
Reply to  Xandros0506

a bit faster, the searched program would already be specified in tasklist as a filter. This will let the tasklist capture the parameters of the programs and send them to the pipeline. Finding needs less to analyze accordingly.

tasklist /fi "ImageName eq msaccess.exe"| find /i "msaccess.exe" || "c:\Program Files\MSOfficeXX.xx\msaccess.exe"
Erzesel
7 months ago

has already delivered the single liner.

If you want to save the occasional manual input, you can also run a small batch which automatically checks at certain time intervals whether the desired process (yet) is running and if necessary performs the necessary measures.

whatchProcess.cmd

echo off
set "WatchProcess=msaccess.exe" &rem zu  beobachtender/restartender Prozess
set "WatchIntervall=600"         &rem Wartezeit zwischen den Prüfungen in Sekunden 
 rem Endlosschleife läuft bis das Fenster geschlossen wird
:loop
    tasklist /fi "ImageName eq %watchprocess%"| find /i "%watchprocess%" >nul || (
        rem  restarte das Programm außerhalb der Batch
        start "" "%watchprocess%"
        timeout 3 >nul   &rem ein paar Sekunden warten, bis das gestartete Programm von tasklist erfasst werden kann 
        goto :loop
    )
    rem  warte bis  zur  nächsten Prüfung
    timeout %WatchIntervall% >nul
    goto loop

Of course, a ProcessWatscher in PowerShell would be much more efficient…