I need to run this command
LEProc.exe -runas ba954abf-2cf7-4efc-90c3-4b6d90aed470 "%~dp0Release\noppack.exe" data script
Next line in batch should be processed after this is finished. Now, there's many ways, bt I'd prefer something as easy as START /WAIT, but no matter how hard I try, running this with START results in
The system cannot find the file specified.
After demon.devin's answer this is the solution:
:CHECK_RUNNING
set errorlevel=
tasklist /fi "imagename eq noppack.exe" | find /i "noppack.exe"> NUL
if /i %errorlevel% GTR 0 goto CONTINUE
ping -n 1 -w 5000 1.1.1.1 > nul
goto CHECK_RUNNING
:CONTINUE
[...]
It looks like LEproc.exe spawns another process.
Then it returns and there is no use waiting for LEproc.exe while you want to know when Noppack.exe is finished.
You should check with tasklist/pslist and a loop (with a delay) if nopppack.exe is still running.
I haven't tested this but maybe this can help..
#echo off
goto begin
:: INFO: Check to see if a process is running and if so wait before launching
:: a new process. After checking for a process this .bat file will wait
:: for a set amount of seconds declared be the user before checking and
:: looping again or moving onto the next command.
:: EDIT: Change "seconds=" to "seconds=15000" to set a time of 15 seconds for
:: the wait period. For 5 seconds change it to "seconds=5000" For extra
:: commands you should add "set app3=AnotherProcess.exe" and repeat for
:: more if need be but be sure to compensate for the new command below.
:begin
:: Set length in seconds here
set seconds=
:: Set your processes here
set app1=noppack.exe
set app2=NewProcess.exe
:: Do not edit
:: First loop check
echo.
echo.
echo Starting the LEProc.exe process...
LEProc.exe -runas ba954abf-2cf7-4efc-90c3-4b6d90aed470 "%~dp0Release\noppack.exe" data script
:check_one
cls
set errorlevel=
tasklist /fi "imagename eq %app1%" | find /i "%app1%"> NUL
if /i %errorlevel% GTR 0 goto complete_one
echo.
echo The %app1% process is running!
echo.
echo Will check again in a few seconds.
echo.
ping -n 1 -w %seconds% 1.1.1.1 > nul
goto check_one
:: First process complete
:complete_one
echo.
echo The %app1% process has finished!
echo.
echo Starting the %app2% process...
START /WAIT %app2%
:: Second loop check
:check_two
cls
set errorlevel=
tasklist /fi "imagename eq %app2%" | find /i "%app2%"> NUL
if /i %errorlevel% GTR 0 goto complete_two
echo.
echo The %app2% process is running!
echo.
echo Will check again in a few seconds.
echo.
ping -n 1 -w %seconds% 1.1.1.1 > nul
goto check_two
:: Second process complete
:complete_two
echo.
echo The %app2% process has finished!
pause
Read the commented section for usage and what to edit.
If #LotPings isn't correct then change app1=noppack.exe to app1=LEProc.exe.
Hope this helps!
=)
Related
Here is the batch program:
#echo off
SETLOCAL EnableDelayedExpansion
set /a incr=0
set arg1=%1
del test_output.csv > NUL 2>&1
del test_output.log > NUL 2>&1
set startTime=%time%
for /d %%i in ("%cd%\*") do call :run_test "%%i"
.\log_parser.exe
type test_output.csv
echo Start Time: %startTime%
echo Finish Time: %time%
exit /B
:run_test
if not "%~nx1" == "shared" (
echo Test: %~nx1
cd %1
del pass_fail_output.csv > NUL 2>&1
echo Running...
cd temp_root_fs
start application.exe
set /a incr=0
:while1
tasklist /fi "IMAGENAME eq application.exe" 2>NUL | find /i /n "application.exe">NUL
if "%ERRORLEVEL%"=="0" (
if %incr% leq 60 (
echo Still running...
timeout /t 1 > NUL 2>&1
set /a incr+= 1
goto :while1
)
echo Test timed out...
taskkill /im application.exe /f
)
echo Test completed...
cd logs
.\pass_fail_parser.exe
type log.log >> ..\..\..\test_output.log
copy pass_fail_output.csv ..\..\
cd ..\..\
)
echo Cleaning...
rmdir /S /Q temp_root_fs
cd ..
)
This is my expected execution:
Loop through folders
Run the application
Wait for 60 seconds and either kill the application after 60 seconds passes or continue if the application finishes
Do some other executions to port log messages into an overall log file
The first loop works fine, but this is what my current output looks like when I execute it:
Test: test1
Initializing...
Running...
Still running...
Still running...
Still running...
Still running...
Still running...
Still running...
Still running...
Still running...
Still running...
Still running...
Test completed...
1 file(s) copied.
Cleaning...
I know this is not working properly because I have 3 more folders for tests, so it should continue on to the other folders, but somehow it seems to break out of the for loop early.
I have read about the /I option that supposedly prevents the goto from breaking out of iff and do loops, but I am not entirely sure how it works (I tried adding it as a parameter but it either errors out or does not seem to do anything).
Any help would be greatly appreciated!
:run_test
if not "%~nx1" == "shared" (
echo Test: %~nx1
cd %1
del pass_fail_output.csv > NUL 2>&1
echo Running...
cd temp_root_fs
start application.exe
set /a incr=0
CALL :while1
echo Test completed...
cd logs
.\pass_fail_parser.exe
type log.log >> ..\..\..\test_output.log
copy pass_fail_output.csv ..\..\
cd ..\..\
)
echo Cleaning...
rmdir /S /Q temp_root_fs
cd ..
)
GOTO :EOF
:while1
tasklist /fi "IMAGENAME eq application.exe" 2>NUL | find /i /n "application.exe">NUL
if "%ERRORLEVEL%"=="0" (
if %incr% leq 60 (
echo Still running...
timeout /t 1 > NUL 2>&1
set /a incr+= 1
goto :while1
)
echo Test timed out...
taskkill /im application.exe /f
)
GOTO :EOF
In your code, if not "%~nx1" == "shared" ( to the final ) is a code block. Labels are not permitted within a code block. The values %var% are replaced when the if statement is parsed by the values of those variables at that time, not as the change due to actions executed within the block. Beware of the delayed expansion trap
The above code converts the :while1 loop to an internal subroutine invoked by CALL :while1 (the colon is required to indicate the call is to an internal label)
Note the GOTO :EOF statements. These transfer execution to the physical end-of-file (the colon is again, required) The first is to prevent execution from proceeding from :run_test into :while1 by flow-through. The second is to force a return to the statement following CALL :while1 when the :while1 routine finishes. The :while1 routine may be placed after any goto statement in the batch's mainline (ie. not a goto within a code block).
I need to create a bat that recognizes if a process is running, and if the process is running I need to add a prompt asking if the user wants to end the process to continue with some other tasks.
I have the command to recognize if a process is running(this is the one that worked for me):
#echo off
tasklist /nh /fi "imagename eq vmware-view.exe" | find /i "vmware-view.exe" >nul && (
echo VMWare Horizon is running
) || (
echo VMWare Horizon is not running
)
pause>nul
and I have the command to prompt for an imput:
#echo off
setlocal
:PROMPT
SET /P AREYOUSURE=Are you sure (Y/[N])?
IF /I "%AREYOUSURE%" NEQ "Y" GOTO END
But I don't know how to put those 2 together to say that, if the process is running, display prompt asking user if bat can end process to continue with an update, and if not running just go on with update.
could you please assist?
thanks in advance
I remember from the old DOS days that you could use GOTOs.
for instance a bat file containing the following:
#ECHO OFF
ECHO something
GOTO LABEL0
ECHO something else
GOTO LABEL1
:LABEL0
ECHO some label
:LABEL1
ECHO some other label
will print:
something
some label
some othe label
you will not see
something else
because the first GOTO skipped to LABEL0
You can use a label like :QUIT or :END at the end of your bat and skip at the end if you have nothing to do.
Use ERRORLEVEL to see if TASKLIST and FIND got the process. Afterwards use CHOICE.
#echo off
set task=vmware-view.exe
tasklist | find /i "%task%" > nul
if %errorlevel%==0 (
echo task is running.
choice /c yn /t 10 /d n /m "should we kill it?"
if errorlevel 2 goto end
taskkill /f /im "%task%"
) else (
echo task is not running.
)
:update
echo updating...
:end
I’m using Jenkins on Windows and want to run csscript that launch an application and execute automatic tests, now I want to create a time out so in case the application is running more than about 30 minutes it will be killed,
I have this batch script: first I create a FOR loop that wait till the application is up and then another FOR loop that check if the application is up more than 25 minutes.
The problem is I’m getting this error in the first loop
Process leaked file descriptors. See http://wiki.jenkins-ci.org/display/JENKINS/Spawning+processes+from+build for more information
I read the info on wiki but didn’t really understand how to solve my issue
Please help
start cscript //nologo D:\tets.vbs
FOR /L %%A IN (1,1,20) DO (
echo Round number %%A
REM find the running executable
tasklist | find /I /C "App.exe" > nul
echo ERRORLEVEL is !ERRORLEVEL!
IF !ERRORLEVEL! EQU 0 EXIT
rem wait 3 seconds
ping 1.1.1.1 -n 1 -w 3000 > nul
)
FOR /L %%U IN (1,1,50) DO (
echo Round number %%U
REM find the running executable
tasklist | find /I /C "App.exe" > nul
echo ERRORLEVEL is !ERRORLEVEL!
if !ERRORLEVEL! EQU 1 EXIT
rem wait 30 seconds
ping 1.1.1.1 -n 1 -w 30000 > nul
)
echo TASKILL
taskkill /f /im App.exe
If you want to timeout a build, use the Build-timeout plugin
Edit:
The suggestion for the article you linked is to use the at command. Instead of:
start cscript //nologo D:\tets.vbs
use
at %time% start cscript //nologo D:\tets.vbs
You will have to calculate the next %time% (in minutes), and obviously the job will have to wait for that minute to start, so at best a 1 second delay, at worse a 59 second delay.
Ok, after seeing crazy stuff being completed in so little code, I have high hopes this is possible.
Pretty much, I want to use the pause command normally, however, if the user doesn't input anything for a specified duration of time, it automatically continues.
In pseudo code:
(sleep %sleep-time%&Echo Pass)1>0 & pause
I thought at first I could do this using start /b to create a process that echoed input while being paused i the current thread, but that could cause problems if the user does input something.
Bonus
What would be really cool is if the errorlevel would be changed based on whether the user inputted something, or if the pause command timed out.
I suggest using timeout:
timeout /T 60 >NUL
This will sleep your script for 1 minute, or unless the user hits a key.
#echo off
setlocal
rem TimedPause.bat - Antonio Perez Ayala
if "%1" equ ":PausePart" goto PausePart
if "%1" neq "" goto begin
echo TimedPause.bat seconds
echo/
echo Wait for given seconds or until user press a key
echo At end, the presence of keyPressed.txt file indicate the cause of exit
goto :EOF
:begin
set seconds=%1
start "" /B "%~F0" :PausePart
for /F "skip=2 tokens=2 delims=," %%a in ('tasklist /FI "IMAGENAME eq cmd.exe" /FO CSV') do (
set PausePart=%%a
goto TimePart
)
:TimePart
ping -n 2 localhost > NUL
if exist keyPressed.txt goto :EOF
set /A seconds-=1
if %seconds% gtr 0 goto TimePart
taskkill /PID %PausePart% /F > NUL
goto :EOF
:PausePart
del keyPressed.txt 2> NUL
pause
echo %time% > keyPressed.txt
exit
How do I create a batch file timer to execute / call another batch through out the day Maybe on given times to run but not to run on weekends ? Must run on system times can also be .cmd to run on xp server 2003
For the timer part of your script i highly reccomend using:
echo.
echo Waiting For One Hour...
TIMEOUT /T 3600 /NOBREAK
echo.
echo (Put some Other Processes Here)
echo.
pause >nul
This script waits for 1 hour (3600 seconds) and then continues on with the script and the user cannot press any buttons to bypass the timer (besides CTRL+C).
You can use
Timeout /t 3600 /nobreak >nul
If you don't want to see a countdown on the screen.
I would use the scheduler (control panel) rather than a cmd line or other application.
Control Panel -> Scheduled tasks
Below is a batch file that will wait for 1 minute, check the day, and then perform an action. It uses PING.EXE, but requires no files that aren't included with Windows.
#ECHO OFF
:LOOP
ECHO Waiting for 1 minute...
PING -n 60 127.0.0.1>nul
IF %DATE:~0,3%==Mon CALL SomeOtherFile.cmd
IF %DATE:~0,3%==Tue CALL SomeOtherFile.cmd
IF %DATE:~0,3%==Wed CALL SomeOtherFile.cmd
IF %DATE:~0,3%==Thu CALL WootSomeOtherFile.cmd
IF %DATE:~0,3%==Fri CALL SomeOtherFile.cmd
IF %DATE:~0,3%==Sat ECHO Saturday...nothing to do.
IF %DATE:~0,3%==Sun ECHO Sunday...nothing to do.
GOTO LOOP
It could be improved upon in many ways, but it might get you started.
The AT command would do that but that's what the Scheduled Tasks gui is for. Enter "help at" in a cmd window for details.
I did it by writing a little C# app that just wakes up to launch periodic tasks -- don't know if it is doable from a batch file without downloading extensions to support a sleep command. (For my purposes the Windows scheduler didn't work because the apps launched had no graphics context available.)
#echo off
:Start
title timer
color EC
echo Type in an amount of time (Seconds)
set /p time=
color CE
:loop
cls
ping localhost -n 2 >nul
set /a time=%time%-1
echo %time%
if %time% EQU 0 goto Timesup
goto loop
:Timesup
title Time Is Up!
ping localhost -n 2 >nul
ping localhost -n 2 >nul
cls
echo The Time is up!
pause
cls
echo Thank you for using this software.
pause
goto Web
goto Exit
:Web
rem type ur command here
:Exit
Exit
goto Exit
#echo off
:Start # seting a ponter
title timer #name the cmd window to "Timer"
echo Type in an amount of time (Seconds)
set /p A= #wating for input from user
set B=1
cls
:loop
ping localhost -n 2 >nul #pinging your self for 1 second
set /A A=A-B #sets the value A - 1
echo %A% # printing A
if %A% EQU 0 goto Timesup #if A = 0 go to ponter Timesup eles loop it
goto loop
:Timesup #ponter Timesup
cls #clear the screen
MSG * /v "time Is Up!" #makes a pop up saying "time Is Up!"
goto Exit #go to exit
:Exit
better code that doesn't involve ping:
SET COUNTER=0
:loop
SET /a COUNTER=%COUNTER%+1
XCOPY "Server\*" "c:\minecraft\backups\server_backup_%COUNTER%" /i /s
timeout /t 600 /nobreak >nul
goto loop
600 seconds is 10 minutes, however you can set it whatever time you'd like
You could also do this>
#echo off
:loop
set a=60
set /a a-1
if a GTR 1 (
echo %a% minutes remaining...
timeout /t 60 /nobreak >nul
goto a
) else if a LSS 1 goto finished
:finished
::code
::code
::code
pause>nul
Or something like that.