Page 1 of 1

A Question About Echo Command

Posted: 14 Jan 2014 22:52
by Chenry
dear all,
I'm confused by command 'echo'.
I want to create a batch file with a script:
::Create Boot.bat
echo @echo off >> D:\Boot\Boot.bat
echo ping 127.0.0.1 -n 1 >nul >> D:\Boot\Boot.bat
echo tasklist ^| find /i "gpupdate.exe" >> D:\Boot\Boot.bat
echo if %errorlevel%==0 taskkill /f /im gpupdate.exe >> D:\Boot\Boot.bat


I want to get a script as below:
@echo off
ping 127.0.0.1 -n 1 >nul
tasklist | find /i "gpupdate.exe"
if %errorlevel%==0 taskkill /f /im gpupdate.exe


How should I change the first script?
Thank you all in advance.

Re: A Question About Echo Command

Posted: 15 Jan 2014 02:14
by Ed Dyreen
Chenry wrote:dear all,
I'm confused by command 'echo'.
I want to create a batch file with a script:
::Create Boot.bat
echo @echo off >> D:\Boot\Boot.bat
echo ping 127.0.0.1 -n 1 >nul >> D:\Boot\Boot.bat
echo tasklist ^| find /i "gpupdate.exe" >> D:\Boot\Boot.bat
echo if %errorlevel%==0 taskkill /f /im gpupdate.exe >> D:\Boot\Boot.bat


I want to get a script as below:
@echo off
ping 127.0.0.1 -n 1 >nul
tasklist | find /i "gpupdate.exe"
if %errorlevel%==0 taskkill /f /im gpupdate.exe


How should I change the first script?
Thank you all in advance.
Assuming delayed expansion is disabled

Code: Select all

::Create Boot.bat
> D:\Boot\Boot.bat (
   echo(@echo off
   echo(ping 127.0.0.1 -n 1 ^>nul
   echo(tasklist ^| find /i "gpupdate.exe"
   echo(if %%errorlevel%%==0 taskkill /f /im gpupdate.exe
)