I am trying to start a program through a batch file wait for some time and then close it. The code i wrote is this
#echo off
xfoil.exe < airfoil.txt > xfoil.out
ping 127.0.0.1 -n 1 -w 10000
taskkill /IM xfoil.exe /F
unfortunately it doesn't work..! I am using Windows 7
Can you please help me out..?
Thank you
Your ping line has a couple of problems. Firstly, the first ping result is always instant, so you should add 1 to the -n switch. Next, 127.0.0.1 is a valid address, so the wait timeout is useless.
Try this instead.
ping -n 11 0.0.0.0 >NUL
That should give you a 10-second pause.
Related
The idea is to have a batch file ping the internet every 5 minutes to see if there is a connection. If there is an internet connection the batch file will loop every 5 minutes to ping again. If there is NO internet connection then the batch file will launch a program and exit. I created a batch file that does everything but exit when the internet is not detected.
What I have so far loops just the way it should but I'm stuck at making the file exit if the internet connection is NOT connected and notepad.exe is launched. I don't know much about batch-files and am trying to piece things together from searches, I need help.
#echo off
setlocal
cls
:loop
#ping 209.222.18.218 -n 1 -w 1000> nul
if %ERRORLEVEL% EQU 1 start C:\windows\notepad.exe
timeout /t 60 >null
goto loop
Expected result: the batch file pings the internet every 5 minutes to detected either there is or isn't an internet connection. If there is an internet connection the batch file will loop every 5 minutes. If there isn't an internet connection the batch file will launch notepad.exe and then exit itself.
Actual result, I get the batch file to loop when it detects internet but I can't get it to exit itself when there is NO internet.
Rearrange your lines a bit:
:loop
timeout 300 >nul
ping 209.222.18.218 -n 1 -w 1000 |find "TTL=" >nul
if %errorlevel%==0 goto :loop
REM if not errorlevel 1 goto :loop
start C:\windows\notepad.exe
Use one of the if lines - whichever you are more comfortable with.
Title description as stated. I'm very novice at this, so please go easy. I've searched articles here, and have tried several iterations of how to do this but my attempts have failed.
I need to run Netstat -anbo every 30 minutes to a text file and keep them rolling for at least 5 files.
Thanks.
Here's how you can run something every few secs in batch script, without the 'sleep' utility.. I will leave the implementation up to you :)
# :loop
REM "do something every 10 secs"
# ping localhost -n 11 > nul
# goto loop
The ping acts as a sleep here.. you can even ping to any non-existent host.
If you want a more accurate time interval, you are better off using
# :loop
REM Execute the MS-DOS dir command ever 20 seconds.
# SLEEP 20
# GOTO loop
For this to work, you will need to have a sleep MS-DOS utility on the computer. You can find it here
You would have to use a simple loop and timeout
A sample implementation
#echo off
:loop
netstat -anbo >> file.txt # >> Will append to file instead of erasing file content
timeout /t 1800 /nobreak # /t timeout in seconds /nobreak Ignore key presses and wait for specified time
goto :loop #Simple loop to keep batch running indefinitely
Remember to run this batch as administrator (For netstat)
I have been dinking around with batch files, and decided to have a little bit of fun creating a command usable in the command line "Hack", which looks like it will make it look like something bad is happening, but nothing really is. Here is the source for that:
#echo off
ECHO Parsing Buffer Strings...
Delay 3000
ECHO Reading Args from FTP Protocol...
Delay 3000
ECHO Interpreting BAUD rate...
Delay 3000
ECHO Reading IBM Standards...
Delay 3000
ECHO Removing Multiplexer matrices...
Delay 3000
ECHO Compiling zip files...
Delay 3000
ECHO Complete. System OS bypassed.
PAUSE
Now, as you may have noticed, there is no built-in "Delay" command, so I made one myself, placing the newly made Batch file in System32 along with Hack.bat:
#echo off
ping 1.1.1.1 -n 1 -w %1 > nul
This takes in one parameter, the amount of delay (ms), and pings a non-existent computer. It tries once to ping it, waiting %1 ms before it gives up. Now, when I put it the command "Hack", it says "Parsing buffer strings", waits three seconds, then the script stops. Now, when I turned echo on to see what the problem was, it said "Parsing buffer strings\nDelay 3000", waited three seconds, then the script stopped. Why? Thank you.
where is your procedure definition and it's call ? you shoud have done someting like :
echo parsing ...
call :delay 3000
echo reading ...
call :delay 3000
exit
:delay
ping 1.1.1.1 -n 1 -w %1 > nul
ping addr -n 1 -w 3000 will only work as long as addr is unreachable. When for some reason the address becomes reachable, the command will return immediately. It will also pollute the network (just a little, but still).
If you don't need millisecond delays, a better approach would be something like this:
#echo off
echo %TIME%
call :delay 5
echo %TIME%
goto :eof
:delay
set /a count=%1+1
ping -n %count% 127.0.0.1 >nul
Output:
C:\>delay.cmd
12:47:44,33
12:47:49,38
ping has a delay of roughly 1 second between two echo requests, so you can sleep for n seconds by sending n+1 echo requests to localhost.
I have this bat file to just kill and start the file, but I need a delay.
TASKKILL /F /IM "file.exe"
(what is the code to delay 1 minute before executing the code below?)
start /d "path" file.exe
Can you please help me? Thanks
You can use ping as #Krister suggested
ping 127.0.0.1 -n 60
of if you are using Vista and above you can use the much easier timeout
timeout /t 60
I have used the ping command to achive this, you could ping an invalid host and set the timeout for the command to your desired delay.
#echo off
ping 1.2.3.4 -n 1 -w 60000 >NUL
# this command will be run after 60000ms
echo 'running';
pause
How can I display my data from x.bat for 5 seconds?
When this code runs, it's impossible for me to see anything, it opens and closes immediately.
#ECHO OFF
:BEGIN
ECHO Authorized user
:END
If I use pause, the user still needs to hit a key to close the screen, that's why this should happen automatically.
#ECHO OFF
:BEGIN
ECHO Authorized user
pause
:END
Thanks
#ECHO OFF
:BEGIN
ECHO Authorized user
timeout 5 >nul
cls
:END
You can grab "sleep.exe" from the Windows Server 2003 resource kit and use sleep [seconds] but the easiest way to get a set delay is to simply ping localhost N+1 times, where N is the number of seconds.
This will sleep for five seconds (there's no delay before the first ping, and a 1s delay after each):
ping -n 6 localhost>nul
SLEEP 5
GOTO:EOF
Would wait for 5 seconds before closing the window.
On Windows Vista and later you can use timeout:
timeout 5 >nul
On ancient Windows versions you need to resort to ping:
ping -n 6 localhost >nul 2>&1
An alternative way to use ping, which also seems to be slightly less precise:
ping -n 1 -w 5000 1.0.0.0 >null
That is, convert seconds to milliseconds and use that as an argument of -w parameter. The -n parameter should have the argument of 1. The host should be a knowingly inaccessible IP address.
variety of ways to resolve this
timeout /t 5 /nobreak >Nul
::for 5 sec
#PING 1.1.1.1 -n 2 -w 3000>nul
:: -n 2 for around 5-6 seconds
sleep 5 (EMERGENCY CASE)