我想创建一个批处理文件,该文件创建一个批处理文件,该文件创建文本文件

发布于 2025-02-05 21:29:25 字数 244 浏览 3 评论 0原文

我想创建一个创建批处理文件2的批处理file1,此批处理文件2应该创建一个txt文件。 以下是我要附加到批处理文件的4行脚本。我需要批处理file1的代码。 请帮助

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

P.S:我是堆栈溢出的新手,只有我的帐户是旧的。到目前为止,我还不知道这是真的 权力,但我已经意识到..(请原谅我是非正式的)

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

入画浅相思 2025-02-12 21:29:29

请参阅如何逃脱字符


batchfile1.batchfile1.batchfile1.bat /em>可以创建第二个批次文件 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

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
汹涌人海 2025-02-12 21:29:29

批处理file2.cmd应该看起来像这样:

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

除非当前目录不可写,否则第一行将创建您的文本文件。如果是这样,您的批处理文件将简单地关闭而无需输入循环。循环中的代码将打印您所需的字符串而不包括任何尾随空间。
为了停止写入文件,您需要输入 ctrl + ctrl c


因此,要从批处理file1.cmd输出它:

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

使用此方法,您只需要逃脱通常的特殊字符,以及任何嵌套的闭合括号。在上面的特殊字符中,是重定向和管子字符。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文