Run TUFLOW From a Batch-file: Difference between revisions
Content deleted Content added
Line 71:
This section is yet to be finalised.
===Creating a delay===
It is possible to create a delay of specified length in a batch file. The best way do this is actually to create a second batch file! To do this create a text file and call it '''wait.bat'''. Within that file enter the following text:
<pre>@ping 127.0.0.1 -n 2 -w 1000 > nul
@ping 127.0.0.1 -n %1% -w 1000> nul</pre>
To create the pause we ping an address for a set time and disregard the output. Once the wait.bat has been created, it can be called from another batchfile using the following syntax:
<pre>call wait <time in seconds.</pre>
In the example below, the first simulation is started and then 60 seconds later (using the wait.bat file) the second simulation is started. Note there is no /wait flag specified, if there was the batchfile would wait for 60 seconds after the first simulation had finished before starting the second simulation.
<pre>Start "TUFLOW" "C:\TUFLOW\Releases\2011-09\w32\TUFLOW_iSP_w32.exe" M01_5m_003.tcf
call wait 60
Start "TUFLOW" /wait "C:\TUFLOW\Releases\2011-09\w32\TUFLOW_iSP_w32.exe" M01_2p5m_005.tcf</pre>
For this to work the wait.bat file needs to be in the same folder as the batchfile calling it. You can put the file in a specific location and add this path as an environment variable. If this is done "call wait <time in seconds> can be added to any batch file.<br>
To set the environment variable, you will need to have administrator access to the machine, and add a colon (;) and then the batchfile location (e.g. ";C:\batch_files\" , without the quotes) in the '''path''' system variables. The separator character is a colon (;) this is added to specify a new path. For more details on modifying the environment please see here: [http://support.microsoft.com/kb/310519 http://support.microsoft.com/kb/310519].
===Variables===
Batch files can be easily setup so that they are more generic and easily customised when moving from one project to another. For example, in the below a variable, TUFLOWEXE, is used to define the path to the TUFLOW exe to be used, and a variable RUN is used to incorporate options such as the /wait so that the simulations run in series (one after the other).
<pre>set TUFLOWEXE=C:\TUFLOW\Releases\2011-09\w64\TUFLOW_iSP_w64.exe
set RUN=start "TUFLOW" /wait "%TUFLOWEXE%" -b
%RUN% MR_H99_C25_Q100.tcf
%RUN% MR_H99_C25_Q050.tcf
%RUN% MR_H99_C25_Q020.tcf</pre>
The advantage of using variables is if the path to the TUFLOW exe changes, or to run a different version of TUFLOW, it is just a simple change in the .bat file. In the above, note the use of quotes around %TUFLOWEXE% in the definition for the RUN variable – quotes are needed around file pathnames whenever they contain a space.
===Looping in a batch file===
Coming soon.
| |||