2

I'm very new with .bat files! But a quick learner.

I'm an engineering student and am working with a wave simulation model. I need to time the computation time, and am trying to do this by setting a variable StartTime=%time% just before I run the simulation, and after the simulation has ended I set EndTime=%time%, and with this I want to calculate the computation time. I run the model by opening a .bat file swashcmd.bat and changing the directory to the folder with my input file file_name.sws and then using the command swashrun file_name.sws.

I've tried to make a .bat file that I run from swashcmd.bat

@echo off

cd %USERPROFILE%\Dropbox\Bachelor\SWASH\testcases\Compiled\a11stwav

set StartTime=%time%

swashrun a11stw01

echo Computation done

set EndTime=%time%

This changes the directory and runs the simulation, but I can't verify that anything afterwards is carried out.

I've tried to make a .bat file that opens swashcmd.bat, and runs the simulation

@echo off
cd C:\Program Files\swash\
swashcmd.bat

cd C:\Users\dk46739\Dropbox\Bachelor\SWASH\testcases\Compiled\a11stwav

This starts the swashcmd.bat but does not change the directory.

It is beyond me to change anything in swashcmd.bat. Is it possible to do what I want without changing the swashcmd.bat file? And which way around (running a .bat from swashcmd.bat or running swashcmd.bat from a .bat) is better? (and why) ^

Opdate 1

With call

cd C:\Program Files\swash\
call swashcmd.bat

cd C:\Users\dk46739\Dropbox\Bachelor\SWASH\testcases\Compiled\a11stwav

Stops after calling swashcmd.bat

Opdate 2

Tried calling my .bat file from swashcmd.bat with cal. EndTime is not stored. Expanding the bat file to output star and end time to a .txt file when saving start and end time works.

2
  • 2
    getTimestamp.bat is a helper batch file to manipulate and measure all sorts of time and date variables and can be found here - dostips.com/forum/viewtopic.php?p=27422#p27422 and it can calculate the elapsed time in varied manners. If your wave simulation is in the order of 5 to 10 seconds then the latency in running batch files could be an issue. Commented Oct 4, 2013 at 12:13
  • If swashrun is a batch file too, you need to execute it with a call command so that the execution returns to swashcmd and set EndTime=... is executed eventually. Also, you are storing both times but are never displaying them (or so it seems). Commented Oct 7, 2013 at 17:37

2 Answers 2

3

Use

CALL swashcmd.bat

Otherwise, control is not returned to the caller.

Sign up to request clarification or add additional context in comments.

Comments

1

Try this and see what is echoed to the screen and if the pause command is reached:

@echo off
cd /d "C:\Program Files\swash\"
call swashcmd.bat
echo "%starttime%"
echo "%endtime%"
echo pause 2
pause
cd /d "C:\Users\dk46739\Dropbox\Bachelor\SWASH\testcases\Compiled\a11stwav"

Try this one too - and tell us if any error messages are on the screen, and if the pause command is reached:

@echo off
cd /d "%USERPROFILE%\Dropbox\Bachelor\SWASH\testcases\Compiled\a11stwav"
set StartTime=%time%
call swashrun a11stw01
echo Computation done
set EndTime=%time%
echo pause 1
pause

3 Comments

swashcmd.bat is called, but starttime and endtime is not stored and pause is not reached.
Something in swashcmd.bat is the issue if no errors are on the screen. Is swashrun a batch file too? If so then use call swashrun a11stw01
using call swashrun %inputfile% works, thank you !! start and end time is stored and pause is reached without eny errors.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.