如何把%的随机%与批处理文件的批处理文件? [英] How to put %random% to a new batch file with a batch file?
问题描述
我想,但这在一个其他.bat文件
I want to but this in to an other .bat file
echo %random% > test.bat
set /a num= +1
:repeat1
set /a num= +1
echo %random% >> test.bat
if ==100 goto end
goto repeat1
所以,我曾尝试与这样的:
So I have tried with this:
echo echo %every%%random%%random%%random%%random% > "output.txt" > test.bat
echo set /a num=%num% +1 >> test.bat
echo :repeat1 >> test.bat
echo set /a num=%num% +1 >> test.bat
echo echo %every%%random%%random%%random%%random% >> "output.txt" >> test.bat
echo if %num%==%amount% goto end >> test.bat
echo goto repeat1 >> test.bat
:end >> test.bat
但%%事情不工作(它将把一个随机nummer,但我希望能有%的随机%的在在新 .bat文件
推荐答案
你有逃避一些字符,如果你想给他们写字面上。他们中的大多数都逃脱以尖号 ^
(&安培;
,<
,>
, |
)。百分号是一个例外:`
you have to escape some chars if you want to write them literally. Most of them are escaped with a caret ^
(&
,<
,>
,|
). The percent sign is an exception: it is escaped with another percent-sign:`
echo %%random%% ^> test.bat
不过,我可以建议其他方法来写你的第二个批处理文件(没有照顾字符逃脱):
But may I suggest another method to write your second bat file (without caring for characters to escape):
@echo off
for /f "delims=:" %%i in (' findstr /n /c:":: Start of Second ::" "%~dpnx0"') do set start=%%i
more +%start% "%~dpnx0" >test.bat
call test.bat
echo -------
type test.txt
echo -------
goto :eof
:: Start of Second ::
@echo off
echo %random% >test.txt
set /a num=0
:repeat1
set /a num+=1
echo %random% >>test.txt
if %num%==10 goto :eof
goto .repeat1
的
的
用于确定数据的开始行被写入,更多+ N
写入文件(〜dpnx0
是当前正在运行的批处理文件),通过跳过第一个 N
行。
The for
is used to determine the start line of the data to be written,
more +n
writes the file ("~dpnx0"
is the currently running batchfile) by skipping the first n
lines.
临:没有必要逃避任何东西 - 只写数据应该输出
Pro: no need to escape anything - just write the data as it should be outputted.
魂斗罗:只有一个第二档的可能;只有静态的文字可能的。
Contra: only one "second file" possible; only static text possible.
这篇关于如何把%的随机%与批处理文件的批处理文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!