Page 1 of 1

small Problem [solved]

Posted: 28 Feb 2012 21:35
by abc0502
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 :)

Re: small Problem

Posted: 28 Feb 2012 22:17
by Captcha142
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

Re: small Problem

Posted: 28 Feb 2012 22:28
by foxidrive
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"

Re: small Problem

Posted: 29 Feb 2012 09:21
by abc0502
Thanks it worked fine :)