Error with creating a .bat file from a batch file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
rasil
Posts: 31
Joined: 23 Apr 2020 13:05

Error with creating a .bat file from a batch file

#1 Post by rasil » 04 Nov 2020 15:56

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 2854 times
Is there any way to fix this issue?

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

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

#2 Post by aGerman » 04 Nov 2020 17:57

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

Post Reply