-2

I want to Create a Batch File1 Which Creates a Batch File2, This Batch File2 Should then Create a txt file. Below is the 4 lines script i Want to Append to Batch File2. I need Code for Batch File1. Please Help

echo > t.txt
:r
echo 101010101010 >> t.txt
goto r

P.S: I am new to Stack Overflow, only my account is old. until now i did not know it's True Powers, but i'm realising.. (excuse me for being informal)

Noam
  • 1,317
  • 5
  • 16

2 Answers2

0

Refer to How to Escape Characters


BATCHFILE1.bat that can create the second batch file BATCHFILE2.bat

@echo off
Title I am the BatchFile1.bat who wants to create the BatchFile2.bat
(
    echo @echo off
    echo echo^>t.txt
    echo :r
    echo echo 101010101010^>^>t.txt
    echo goto r
)>BATCHFILE2.bat
Hackoo
  • 18,337
  • 3
  • 40
  • 70
  • Thank you soo much @Hackoo , You have no idea how much you've helped me, for any Help Please Contact me : t.me/swap72 I'll be more than happy to help you back. – Swapnil Mishra Jun 08 '22 at 17:26
  • @SwapnilMishra Welcome on StackOverflow ! Please take Stack Overflow (SO) [tour](https://stackoverflow.com/tour) to learn how to say thanks on SO by accepting an answer on being helpful by clicking on gray Check mark symbol left to an answer. See also [How does accepting an answer work?](https://meta.stackexchange.com/questions/5234/) A question with no accepted answer is rated as a not answered question even if there are good answers. – Hackoo Jun 08 '22 at 17:48
  • i don't have enough reputations to vote an answer but my feedback has been recorded. – Swapnil Mishra Jun 08 '22 at 19:06
  • @SwapnilMishra i mean accept an answer not to vote ! by clicking on gray Check mark symbol left to an answer – Hackoo Jun 08 '22 at 19:10
  • Sorry, Done!.... @Hackoo Where can i PM/DM or Follow You on Social Platforms?? – Swapnil Mishra Jun 08 '22 at 19:32
0

Batch File2.cmd should look like this:

@CD . 1>"t.txt" 2>NUL || Exit /B
:r
@(Echo 101010101010) 1>>"t.txt"
@GoTo r

The first line will create your text file, unless the current directory is not writeable. Should that be the case, your batch file will simply close without entering the loop. The code in the loop will print your required string without including any trailing spaces.
In order to stop writing to the file, you will need to enter Ctrl+C


Therefore to output it from Batch File1.cmd you'd need:

@(
    Echo @CD . 1^>"t.txt" 2^>NUL ^|^| Exit /B
    Echo :r
    Echo @(Echo 101010101010^) 1^>^>"t.txt"
    Echo @GoTo r
) 1>"Batch File2.cmd"

Using this method, you simply need to escape the usual special characters, plus any nested closing parentheses. In the above your special characters are the redirection and pipe characters.

Compo
  • 36,585
  • 5
  • 27
  • 39
  • Thank You Soo Much @Compo I was in need of help Since Very long Ever Since i've figured out how to use stackoverflow People have stopped calling me Mad. I hope there are more legends like Compo and Hackoo out there. Cheers. – Swapnil Mishra Jun 08 '22 at 17:34