1.

Solve : Using a Batch file to create another batch file?

Answer»

Hi, guys.

I'm new to batch scripting. I'm trying to create a batch file that will create another batch file based on a user input but am having problems with the "echo" command. The controlling batchfile (say create.bat) takes in a parameter and echos a list of lines into the new file. However, the new file is also supposed to take new parameters in when run and hence needs to have lines in it to do that.

The problem is that if you have a '%' after the echo in the batch file, it treats it as a parameter but I want it as text. How can I FORCE it to treat the % as a text?

All help appreciated


Here is a sample:

set DCRNUMBER = %1


mkdir cr%DCRNUMBER%

cd cr%DCRNUMBER%


echo @echo off >cr%DCRNUMBER%_run.bat
echo. >>cr%DCRNUMBER%_run.bat
echo set PROGNAME=cr1217_run.bat >>cr%DCRNUMBER%_run.bat
echo set CRNAME=cr1217 >>cr%DCRNUMBER%_run.bat
echo. >>cr%DCRNUMBER%_run.bat
echo if (%3)==() goto USAGE >>cr%DCRNUMBER%_run.bat
echo. >>cr%DCRNUMBER%_run.bat
echo set USERID=%1 >>cr%DCRNUMBER%_run.bat
echo set PASSWD=%2 >>cr%DCRNUMBER%_run.bat
echo set DBNAME=%3 >>cr%DCRNUMBER%_run.bat

You do not need to use % as a literal thing in the echo command.

Rethink what you are doing. Do it the other way and it will be easy.

The % is used for a special purpose. The ^ character tells the interpreter to treat the next character as a literal, not a special character, so the first line of your example would be created by
Code: [Select]Echo set DCRNUMBER = ^%1 >MyNewBatch.batDo my eyes deceive me or are you replying to a post made in 2004 by someone who is no longer a member?

Quote

Posted by: Nowsor Mirza Posted on: 26-05-2004, 23:28:20
I DIDNT spot the date ... just replying in my usual helpful way !doesn't it say "warning you are posting to a topic that is more than 30 days old!" I don't think so...i knew i saw it

[attachment deleted by ADMIN]Never seen that before. Oh well.


Discussion

No Comment Found