I have a bat script file with many instructions. One of them takes so much time and i want to know how much time the execution takes.
In Unix this is so simple with the prefix 'time'.
Thanks in advance.
The best solutions is to use the command
Measure-Command {copy *.* d:\dossier\}
Related
Currently, I'm working with a finite element software called DIANA, I've been always capable of running "simple" models with MATLAB executing a batch file. Nevertheless, now I'm starting to use more "complex" models (just more robust, with more elements), but the procedure is exactly the same to the one that I've been using before. The problem is that now I can't run the model from MATLAB, it apparently start to run it, but stops suddenly. I'm using the next commands:
dos('path\filename.bat')
or
system(fullfile(path,'filename.bat' ))
Both lines execute the .bat file. I thought that I had something wrong with the files, so I reviewed them but apparently there's nothing wrong with them. Then I just made double click on the .bat file, and the procedure runs without problems. Then I realized that the problem wasn't the files, it was the execution from MATLAB. Now that you know the context of the problem, can you giving me some advice in order to avoid that MATLAB "kills" the process internally?
The trace of execution showed in MATLAB:
diana: working directory is *CURRENT DIRECTORY NAME*
diana: input file is *FILENAME*.dat
diana: command file is *FILENAME*.dcf
diana: output file is *FILENAME*.out
diana: filos file is diana.ff
DIANA JOB 8028 finished
The trace execution making directly double click in the batch file is the following:
In the remarked files showed in the previous figure, are contained the output of the model, while executing directly from MATLAB, those don't appear, because MATLAB finish the process before.
Thanks in advance for any answer!
Pd: I'm using a computer with the next characteristics: Windows7, 12 Gb RAM, OS 64bits, Processor Intel Xeon 2.53 GHz.
What you are running is not strictly equivalent to a double click on the .bat file, specially because current directory is different, and if the batch file needs to access to auxiliary files (relative path), then the files won't be found.
Try adding this in your batch file as the first command (or right after echo off)
Cd /d %~dp0
Here is the solution provided by Diana support team:
It seems that MATLAB sets some environment symbols that limit the
memory usage per thread.
When you start Diana from Matlab via a batch file that resets the
symbols all works fine.
Such a batch file may look like:
rem === Diana Environment Setup ===
call "C:\Program Files\Diana 10.0\dialogin.bat"
rem Unset the symbols added by MATLAB
set KMP_STACKSIZE=
set KMP_HANDLE_SIGNALS=
set KMP_BLOCKTIME=
rem start the diana job
diana test2
I am a beginner at batch programming and I'm wondering if it is possible to run a batch file along with just one command already executed and accept a command from the user and execute it.
For example this is what I want to happen:
1) Run batch file
2) Type one command and press enter. The command executes.
But I want that all to happen just by running the batch file by itself.
This might be a very simple task to most of you but I've searched and can't get a solid solution.
Help is greatly appreciated. Thank you.
set /p Variab=Command_here:
%Variab%
This will take input to Variab and then execute the input.
Short story: need a method to get the write-status of a file on a server (using BASH) from a client (using CMD batch).
Long-time lurker, first-time poster. I did many searches on variations of what I'm looking for and have not yet found enough data.
I am writing a batch file in CMD (because the clients could be any WinOS [XP - up] with unknown packages installed). The batch uses puTTY's "plink" to connect via SSH to the server. Once connected to the server, plink executes a command to write data to a new file.
Once that file is written, I use PSCP to copy the file to the client
So far, so good; I have successfully accomplished all of this.
The creation of that file is instantaneous but the time it takes to write all of the data is unknown / variable. Therefore I need an automated method to determine when the file is complete, to then copy it. Simply using timeout/sleep for XX seconds is not feasible in my circumstances.
The approach I have taken so far (as of yet unsuccessfully) is to repeatedly grab the filesize using "stat -c '%s' filemane" and run that in a loop until grab1 EQU grab2, indicating a complete file. I am finding this difficult because I can't get the output of stat into the CMD batch to process it.
Q1: Is this (stat result going into CMD for loop) the best approach? Maybe there's something existing in BASH?
Q2: if Q1 is true, any ideas on how to get the stat result into the CMD batch as a variable to parse/analyze the data?
Thanks in advance for suggestions and your time.
DCT
Have the command writing the file write it with a temp filename. So if it will be called xyz.txt, have it written with filename tmpxyz.txt.tmp, then the final step will be a rename.
That way you can just check for the presence of the named file.
Usually a good idea to give the file a unique name, probably incorporating the date and time, I find.
I have a shared disk that I would like to clean up once per week using a scheduled task of some sort. I would like to use a batch script so that the system admins can easily modify it or reuse it on other directories when needed.
The directory has files with multiple file extensions but the ones that need to be deleted end in .bkf and must be over 2 weeks old.
Does anyone have a batch script solution for this windows server (not sure which version)?
If you have PowerShell (or can install it), check out this link: http://thepowershellguy.com/blogs/posh/archive/2007/12/13/hey-powershell-guy-how-can-i-delete-files-that-are-a-specified-number-of-hours-old.aspx
Take a look at this page - scheduling tasks from command line
It shows you hot to create scheduled tasks from the command line. You might be able to use this in combination with other dos commands to get your result.
The only thing that needs to be in the batch file is
#echo off
cls
del C:\some\directory\*.bkf
And the delete path can also be sent to this batch script as an argument so that the directory is changeable.
I ended up just writing an EXE that accepts parameters and scheduling that. Unfortunately the other solutions didn't have the flexibility needed.
have you looked into forfiles.exe?
http://blog.stevienova.com/2007/02/27/forfiles-delete-files-older-than-x-amount-of-days/
I am writing a batch file, in which I call an EXE to execute. Now, statements after the call to the EXE should not execute till the EXE completes its execution. How can I do it in the batch file (on Windows)?
START /WAIT First.exe
START /WAIT Second.exe
It depends on how the .exe works. I'm afraid I don't have all the technical details or terminology, but some .exe files will return control of the session immediately after they've started, while others won't return control until after the program has terminated.
The second case is easy as the commands late in the file won't execute until the former have completed, so I'll assume you're facing case #1.
An easy workaround/hack if the execution takes (approximately) the same amount of time every time it runs is to use a ping command with a delay.
PING 127.0.0.1 -n 1 -w 120000 >NUL
This will force the ping command to run once with a 120000ms (2 min) delay.
There's also a good article on a more complex (but more reliable method) on fpschultze.de with a much more detailed explanation. In short you query the task list searching for the executable you're waiting for. As soon as it's not there you carry on with the batch file. It also uses the ping method, but in a different manner.
The statements in a batch file are executed sequentially. So if your batch file looks like:
first.exe
next.exe
Next is executed if first is completed.
You could use the "start" command with parameter /wait
use start /? on commandline for details.
Here is the very simple process. Just keep the following line to wait for 10 secs and then continue the other commands...
TIMEOUT /T 10
That's all you have to do. I hope you enjoy my technique.
You can use
PAUSE
In batch scripting, but I don't understand your question.