我一直在使用这个批处理代码:https://github.com/ITCMD/in2batch它会输出如下内容:
(
echo gfgqebfwrwe
echo grgrgehrg4wer
echo htrehteertrehrt
+12,000 more lines of that
) >>outputfile.txt
(这是实际的文件) 但是程序只是关闭了。它在第 10,692 行停止,并显示echo
。它停止的行或之后的行上没有特殊字符。批处理是否限制单个 内可以输出多少行()
?
答案1
事实上,未经调整的运行临时共享脚本导致cmd
应用程序错误和异常代码崩溃0xc00000fd
,这意味着堆栈溢出(奇怪的是 - 如果重复运行它会停在不同的行例如10692
/ 10711
/10707
所以我不能给出任何精确的回答关于括号中的行数限制)。
幸运的是,重定向输出时没有发生错误for
环形。
因此,对原始脚本进行以下细微更改可获得预期效果。调整后的脚本在一个简单的for /F
循环中解析自身,并且仅执行和echo
之间的命令(参见以下行:BEGIN CERTIFICATE
END CERTIFICATE
5..16)
@echo off
SETLOCAL enableextensions
if exist "7za.exe" goto :10897117303211127370517328436
echo creating file . . .
set "_out="
(
for /f "usebackq tokens=*" %%G in ("%~f0") do (
if "%%~G"=="echo -----BEGIN CERTIFICATE-----" set "_out=yes"
if defined _out %%~G
if "%%~G"=="echo -----END CERTIFICATE-----" set "_out="
)
)>temp.txt
certutil -v -decode "temp.txt" "7za.exe"
REM >nul
REM del /f /q "temp.txt"
goto :10897117303211127370517328436
(
echo -----BEGIN CERTIFICATE-----
echo TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
echo AAAAAAAAAAAAAAAA+AAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5v
… truncated 12000+ lines of that …
echo AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
echo AAAAAAAAAAAAAAAAAAAAAA==
echo -----END CERTIFICATE-----
)>temp.txt
certutil -v -decode "temp.txt" "7za.exe" >nul
del /f /q "temp.txt"
:10897117303211127370517328436
pause
输出:
d:\bat> erase 7za.exe 2>nul
d:\bat> D:\bat\SU\tempShare.bat
creating file . . .
Input Length = 808252
Output Length = 587776
CertUtil: -decode command completed successfully.
Press any key to continue . . .
d:\bat> 7za.exe -?
7-Zip (A) 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18
Usage: 7za <command> [<switches>...] <archive_name> [<file_names>...]
[<@listfiles...>]
… (truncated) …
下面的代码tempShareExitLoop.bat
执行相同的操作,但在到达该行后停止读取END CERTIFICATE
。重要提示:将该过程插入到代码中:OutCertificate
某个位置(紧靠)下方。goto :eof
@echo off
SETLOCAL enableextensions
if exist "7za.exe" goto :10897117303211127370517328436
echo creating file . . .
>temp.txt call :OutCertificate
certutil -v -decode "temp.txt" "7za.exe"
REM >nul
REM del /f /q "temp.txt"
goto :10897117303211127370517328436
(
echo -----BEGIN CERTIFICATE-----
echo TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
echo AAAAAAAAAAAAAAAA+AAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5v
… truncated 12000+ lines of that …
echo AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
echo AAAAAAAAAAAAAAAAAAAAAA==
echo -----END CERTIFICATE-----
)>temp.txt
certutil -v -decode "temp.txt" "7za.exe" >nul
del /f /q "temp.txt"
:10897117303211127370517328436
pause
goto :eof
:OutCertificate
set "_out="
for /f "usebackq tokens=*" %%G in ("%~f0") do (
if "%%~G"=="echo -----BEGIN CERTIFICATE-----" set "_out=yes"
if defined _out %%~G
if "%%~G"=="echo -----END CERTIFICATE-----" goto :eof
)
goto :eof