Page 1 of 1

Error with creating a .bat file from a batch file

Posted: 04 Nov 2020 15:56
by rasil
Hi everyone!

Here i just want to create a simple batch file called d.bat from a batch file.

Code: Select all

@echo off
echo @echo off>d.bat
echo :l>d.bat
echo if exist d.d goto a>d.bat
echo goto l>d.bat
echo :a>d.bat
echo start x.bat>d.bat
pause
exit
But when I run this batch file all i get in the output batch file is just the last line (start x.bat)
Captudre.PNG
Captudre.PNG (3.01 KiB) Viewed 2858 times
Is there any way to fix this issue?

Re: Error with creating a .bat file from a batch file

Posted: 04 Nov 2020 17:57
by aGerman
I recommend you to write the redirection at the beginning of the line to make it more readable (and to avoid a couple of side effects).
Although your main issue is that you use > all the time. > creates/overwrites a file. >> appends to a file.
Something about like that

Code: Select all

@echo off
 >"d.bat" echo @echo off
>>"d.bat" echo :l
>>"d.bat" echo if exist "d.d" goto a
>>"d.bat" echo goto l
>>"d.bat" echo :a
>>"d.bat" echo start "" "x.bat"
pause
Steffen