Jump to content

Using batch file to shutdown on completion

Recommended Posts

Using batch files it is possible to shutdown your computer at the end of the a series of TUFLOW simulations.  There are a number of ways of doing this.  If you have only a single batchfile running you can add the following at the end of your batch file:

shutdown.exe /s /t 30


This will shutdown the computer (/s for shutdown, /r for restart) with 30 seconds warning (/t 30).  For example, the batch file below, uses the event / scenario features in TUFLOW to run 5 design event magnitudes, for 5 durations and 3 topography configurations (75 total simulations) and at the end of this the computer will shutdown:

set A=Q010 Q020 Q050 Q100 Q200
set B=10min 30min 60min 120min 270min
set C=Exg Dev Mit

FOR %%a in (%A%) do (
    FOR %%b in (%B%) do (
        FOR %%c in (%C%) do (
            start "TUFLOW" /wait TUFLOW_iSP_w64.exe -e1 %%a -e2 %%b -s1 %%c filename_~e1~_~e2~_~s1~.tcf

shutdown.exe /s /t 30


Another option if a shared modelling resource (which may be running multiple batch files) is to monitor the number of "TUFLOW" processing in the task manager and when this is zero to shutdown the computer.  The following batch file does exactly that!

echo off

    set /a count=0
    for /f %%x in ('tasklist ^| find /c "TUFLOW"') do set count=%%x
    IF %count%==0 (
		shutdown.exe /s /t 30
	) ELSE (
        timeout 60
        goto do_while_loop_start

This batch file counts the number of processes with "TUFLOW" in the process name and if this is greater than 0, a delay of 60 seconds is created and the loop started again. If no "TUFLOW" simulations are running a shutdown command is issued.


Note, that this only takes into account the number of TUFLOW simulations, so be careful if of number crunching is done on the machine.  To test the batch file, change the "shutdown.exe /s /t 30" to "echo shutdown.exe /s /t 30".  This will simply display the line to the console window rather the actually processing the shutdown.


See also the batch file page on the TUFLOW wiki:





Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...