View unanswered posts | View active topics It is currently 20 Sep 2014 10:00



Post new topic Reply to topic  [ 4 posts ] 
small Problem [solved] 
Author Message

Joined: 26 Oct 2011 22:38
Posts: 1007
Location: Egypt
Post small Problem [solved]
This is My Test Batch File:
This is a Batch That Make Another Batch
Code:

>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.



28 Feb 2012 21:35
Profile

Joined: 18 Sep 2011 23:35
Posts: 13
Post Re: small Problem
To sucessfully make batch files from batch files, you need to employ the escape character ^

instead of
Code:
echo.START /max %ComSpec% /c "%Temp%\md5.exe"

use
Code:
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:
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:
>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


28 Feb 2012 22:17
Profile

Joined: 10 Feb 2012 02:20
Posts: 4188
Post Re: small Problem
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"


28 Feb 2012 22:28
Profile

Joined: 26 Oct 2011 22:38
Posts: 1007
Location: Egypt
Post Re: small Problem
Thanks it worked fine :)


29 Feb 2012 09:21
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 


Who is online

Users browsing this forum: Bing [Bot], tcpman and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Forum style by Vjacheslav Trushkin for Free Forums/DivisionCore.