Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
abc0502
- Posts: 1007
- Joined: 26 Oct 2011 22:38
- Location: Egypt
#1
Post
by abc0502 » 28 Feb 2012 21:35
This is My Test Batch File:
This is a Batch That Make Another Batch
Code: Select all
>Main.bat (
echo.@ECHO OFF
echo.CLS
echo.TITLE Test Batch
echo.START /max %ComSpec% /c "%Temp%\md5.exe"
echo.Ping localhost -n 1 -w 1 >nul
echo.EXIT
)
>>NewFile.bat
type NewFile.bat
The firt Problem is:
the %ComSpec% always appear in the NewFile.bat As "C:\Windows\system32\cmd.exe" and the %temp% Appear as "C:\Users\Admin\AppData\Local\Temp"
is there away that make them appear as i wrote in the Main.bat
The second:
The Ping line when i end it with >nul the line dosn't appear and when i remove >nul it appear
and i want the entire line to be written in the file as in the code up there ... any one knows
thanks in advance
Last edited by
abc0502 on 12 Mar 2012 00:30, edited 1 time in total.
-
Captcha142
- Posts: 13
- Joined: 18 Sep 2011 23:35
#2
Post
by Captcha142 » 28 Feb 2012 22:17
To sucessfully make batch files from batch files, you need to employ the escape character ^
instead of
Code: Select all
echo.START /max %ComSpec% /c "%Temp%\md5.exe"
use
Code: Select all
echo.START /max ^%%ComSpec^%% /c ^"^%%Temp^%%\md5.exe^"
(percent signs like to be odd in batch)
EDIT:
just saw part about ping :
again use
Code: Select all
echo.Ping localhost -n 1 -w 1 ^>nul
I also removed the return carriage after the block b/c that changed the file being written to . . .
end code should look like:
Code: Select all
>Main.bat (
echo.@ECHO OFF
echo.CLS
echo.TITLE Test Batch
echo.START /max ^%%ComSpec^%% /c ^"^%%Temp^%%\md5.exe^"
echo.Ping localhost -n 1 -w 1 >nul
echo.EXIT
)>>NewFile.bat
type NewFile.bat
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#3
Post
by foxidrive » 28 Feb 2012 22:28
Captcha142 has almost told you the right story.
There is no need to escape % or " below, just double the % to %% and it will work.
echo.START /max %%ComSpec%% /c "%%Temp%%\md5.exe"
-
abc0502
- Posts: 1007
- Joined: 26 Oct 2011 22:38
- Location: Egypt
#4
Post
by abc0502 » 29 Feb 2012 09:21
Thanks it worked fine