I would like to open few large files (word, excel, power-point etc) using a Windows batch file and I would like to record if the operation passed or failed. If it passed I would like to write to the log. All that I have done is below, however, I am unable to measure the time it is taking for opening the files. I tried few scripts but they all failed.
please can you help me
echo StartTime = %Time% >> C:\Users\abc\Desktop\time.log
start winword.exe && (
echo Pass: MS Word opened at: %date% %time% >> C:\Users\abc\Desktop\time.log
) || (
echo Fail: MS Word Errored at: %date% %time% >> C:\Users\abc\Desktop\time.log
)
echo EndTime = %Time% >> C:\Users\abc\Desktop\time.log
echo StartTime = %Time% >> C:\Users\abc\Desktop\time.log
start excel.exe && (
echo Pass: MS Excel opened at: %date% %time% >> C:\Users\abc\Desktop\time.log
) || (
echo Fail: MS Excel Errored at: %date% %time% >> C:\Users\abc\Desktop\time.log
)
echo EndTime = %Time% >> C:\Users\abc\Desktop\time.log
here's bat file that returns the milliseconds passed since 1970 of when the file is last accessed ( lastaccessed.bat
) that takes a single argument - the file:
@if (@x)==(@y) @end /***** jscript comment ******
@echo off
cscript //E:JScript //nologo "%~f0" %*
exit /b %errorlevel%
@if (@x)==(@y) @end ****** end comment *********/
var FileSystemObj = new ActiveXObject("Scripting.FileSystemObject");
var ARGS = WScript.Arguments;
var filename=ARGS.Item(0);
var FileSystemObj = new ActiveXObject("Scripting.FileSystemObject");
function getLastAccessed(obj){
return obj.DateLastAccessed;
}
var file=FileSystemObj.GetFile(filename);
WScript.Echo((new Date(file.DateLastAccessed)).getTime());
Here's the jeval.bat by dbenham:
@if (@X)==(@Y) @end /* harmless hybrid line that begins a JScrpt comment
::************ Documentation ***********
:::
:::jEval JScriptExpression [/N]
:::jEval /?
:::
::: Evaluates a JScript expression and writes the result to stdout.
:::
::: A newline (CR/LF) is not appended to the result unless the /N
::: option is used.
:::
::: The JScript expression should be enclosed in double quotes.
:::
::: JScript string literals within the expression should be enclosed
::: in single quotes.
:::
::: Example:
:::
::: call jEval "'5/4 = ' + 5/4"
:::
::: Output:
:::
::: 5/4 = 1.25
:::
::************ Batch portion ***********
@echo off
if "%~1" equ "" (
call :err "Insufficient arguments"
exit /b
)
if "%~2" neq "" if /i "%~2" neq "/N" (
call :err "Invalid option"
exit /b
)
if "%~1" equ "/?" (
setlocal enableDelayedExpansion
for /f "delims=" %%A in ('findstr "^:::" "%~f0"') do (
set "ln=%%A"
echo(!ln:~3!
)
exit /b
)
cscript //E:JScript //nologo "%~f0" %*
exit /b
:err
>&2 echo ERROR: %~1. Use jeval /? to get help.
exit /b 1
************ JScript portion ***********/
if (WScript.Arguments.Named.Exists("n")) {
WScript.StdOut.WriteLine(eval(WScript.Arguments.Unnamed(0)));
} else {
WScript.StdOut.Write(eval(WScript.Arguments.Unnamed(0)));
}
Here's how you can calculate the passed time (in secconds) between two openings of a file:
@echo off
for /f %%a in ('lastaccessed.bat "c:\My Folder\book1.xlsx"') do set "time1=%%a"
excel.exe "c:\My Folder\book1.xlsx"
for /f %%a in ('lastaccessed.bat "c:\My Folder\book1.xlsx"') do set "time2=%%a"
call jeval.bat "(%time2% - %time1%)/1000"
Is this what you looking for?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.