Does batch's parentheses have a limit to how much output it can hold?












1















I have been using this batch code: https://github.com/ITCMD/in2batch and it outputs something that looks like this:



(
echo gfgqebfwrwe
echo grgrgehrg4wer
echo htrehteertrehrt
+12,000 more lines of that
) >>outputfile.txt


(here is the actual file)
However the program just closes. It stops on line 10,692 with echo. There are no special characters on the line it stops on, or the line after. Does batch have a limit to how many lines of output can be inside a single ()?










share|improve this question

























  • Sounds like some of echo … line contains an unescaped closing parenthesis ). Check presence of any cmd-poisonous character like & , <, >, ^ or | as well.

    – JosefZ
    Jan 9 at 12:56











  • So now, it's not even putting any into a file. It is just echoing it all onto the screen. It stops on line 10692 (echo AAAAAAAAAAD/////JDhHACAFkxkCAAAA0OFHAAAAAAAAAAAAAAAAAAAAAAAAAAAA) then crashes. the output file is not even created. Here is what I am running: github.com/ITCMD/ITCMD-STORAGE/raw/master/tempShare.bat

    – Mark Deven
    Jan 9 at 13:02













  • You are right. Event Viewer shows Exception Code 0xc00000fd which means Stack overflow. As a workaround, divide parenthesized block to parts of less echo lines each (e.g. 2000 = very gingerly limit).

    – JosefZ
    Jan 9 at 15:39











  • @JosefZ thanks. I can just group each line in parentheses

    – Mark Deven
    Jan 9 at 17:41
















1















I have been using this batch code: https://github.com/ITCMD/in2batch and it outputs something that looks like this:



(
echo gfgqebfwrwe
echo grgrgehrg4wer
echo htrehteertrehrt
+12,000 more lines of that
) >>outputfile.txt


(here is the actual file)
However the program just closes. It stops on line 10,692 with echo. There are no special characters on the line it stops on, or the line after. Does batch have a limit to how many lines of output can be inside a single ()?










share|improve this question

























  • Sounds like some of echo … line contains an unescaped closing parenthesis ). Check presence of any cmd-poisonous character like & , <, >, ^ or | as well.

    – JosefZ
    Jan 9 at 12:56











  • So now, it's not even putting any into a file. It is just echoing it all onto the screen. It stops on line 10692 (echo AAAAAAAAAAD/////JDhHACAFkxkCAAAA0OFHAAAAAAAAAAAAAAAAAAAAAAAAAAAA) then crashes. the output file is not even created. Here is what I am running: github.com/ITCMD/ITCMD-STORAGE/raw/master/tempShare.bat

    – Mark Deven
    Jan 9 at 13:02













  • You are right. Event Viewer shows Exception Code 0xc00000fd which means Stack overflow. As a workaround, divide parenthesized block to parts of less echo lines each (e.g. 2000 = very gingerly limit).

    – JosefZ
    Jan 9 at 15:39











  • @JosefZ thanks. I can just group each line in parentheses

    – Mark Deven
    Jan 9 at 17:41














1












1








1


1






I have been using this batch code: https://github.com/ITCMD/in2batch and it outputs something that looks like this:



(
echo gfgqebfwrwe
echo grgrgehrg4wer
echo htrehteertrehrt
+12,000 more lines of that
) >>outputfile.txt


(here is the actual file)
However the program just closes. It stops on line 10,692 with echo. There are no special characters on the line it stops on, or the line after. Does batch have a limit to how many lines of output can be inside a single ()?










share|improve this question
















I have been using this batch code: https://github.com/ITCMD/in2batch and it outputs something that looks like this:



(
echo gfgqebfwrwe
echo grgrgehrg4wer
echo htrehteertrehrt
+12,000 more lines of that
) >>outputfile.txt


(here is the actual file)
However the program just closes. It stops on line 10,692 with echo. There are no special characters on the line it stops on, or the line after. Does batch have a limit to how many lines of output can be inside a single ()?







command-line batch memory-limit






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 9 at 13:58







Mark Deven

















asked Jan 8 at 23:06









Mark DevenMark Deven

570122




570122













  • Sounds like some of echo … line contains an unescaped closing parenthesis ). Check presence of any cmd-poisonous character like & , <, >, ^ or | as well.

    – JosefZ
    Jan 9 at 12:56











  • So now, it's not even putting any into a file. It is just echoing it all onto the screen. It stops on line 10692 (echo AAAAAAAAAAD/////JDhHACAFkxkCAAAA0OFHAAAAAAAAAAAAAAAAAAAAAAAAAAAA) then crashes. the output file is not even created. Here is what I am running: github.com/ITCMD/ITCMD-STORAGE/raw/master/tempShare.bat

    – Mark Deven
    Jan 9 at 13:02













  • You are right. Event Viewer shows Exception Code 0xc00000fd which means Stack overflow. As a workaround, divide parenthesized block to parts of less echo lines each (e.g. 2000 = very gingerly limit).

    – JosefZ
    Jan 9 at 15:39











  • @JosefZ thanks. I can just group each line in parentheses

    – Mark Deven
    Jan 9 at 17:41



















  • Sounds like some of echo … line contains an unescaped closing parenthesis ). Check presence of any cmd-poisonous character like & , <, >, ^ or | as well.

    – JosefZ
    Jan 9 at 12:56











  • So now, it's not even putting any into a file. It is just echoing it all onto the screen. It stops on line 10692 (echo AAAAAAAAAAD/////JDhHACAFkxkCAAAA0OFHAAAAAAAAAAAAAAAAAAAAAAAAAAAA) then crashes. the output file is not even created. Here is what I am running: github.com/ITCMD/ITCMD-STORAGE/raw/master/tempShare.bat

    – Mark Deven
    Jan 9 at 13:02













  • You are right. Event Viewer shows Exception Code 0xc00000fd which means Stack overflow. As a workaround, divide parenthesized block to parts of less echo lines each (e.g. 2000 = very gingerly limit).

    – JosefZ
    Jan 9 at 15:39











  • @JosefZ thanks. I can just group each line in parentheses

    – Mark Deven
    Jan 9 at 17:41

















Sounds like some of echo … line contains an unescaped closing parenthesis ). Check presence of any cmd-poisonous character like & , <, >, ^ or | as well.

– JosefZ
Jan 9 at 12:56





Sounds like some of echo … line contains an unescaped closing parenthesis ). Check presence of any cmd-poisonous character like & , <, >, ^ or | as well.

– JosefZ
Jan 9 at 12:56













So now, it's not even putting any into a file. It is just echoing it all onto the screen. It stops on line 10692 (echo AAAAAAAAAAD/////JDhHACAFkxkCAAAA0OFHAAAAAAAAAAAAAAAAAAAAAAAAAAAA) then crashes. the output file is not even created. Here is what I am running: github.com/ITCMD/ITCMD-STORAGE/raw/master/tempShare.bat

– Mark Deven
Jan 9 at 13:02







So now, it's not even putting any into a file. It is just echoing it all onto the screen. It stops on line 10692 (echo AAAAAAAAAAD/////JDhHACAFkxkCAAAA0OFHAAAAAAAAAAAAAAAAAAAAAAAAAAAA) then crashes. the output file is not even created. Here is what I am running: github.com/ITCMD/ITCMD-STORAGE/raw/master/tempShare.bat

– Mark Deven
Jan 9 at 13:02















You are right. Event Viewer shows Exception Code 0xc00000fd which means Stack overflow. As a workaround, divide parenthesized block to parts of less echo lines each (e.g. 2000 = very gingerly limit).

– JosefZ
Jan 9 at 15:39





You are right. Event Viewer shows Exception Code 0xc00000fd which means Stack overflow. As a workaround, divide parenthesized block to parts of less echo lines each (e.g. 2000 = very gingerly limit).

– JosefZ
Jan 9 at 15:39













@JosefZ thanks. I can just group each line in parentheses

– Mark Deven
Jan 9 at 17:41





@JosefZ thanks. I can just group each line in parentheses

– Mark Deven
Jan 9 at 17:41










1 Answer
1






active

oldest

votes


















1














Indeed, running unadjusted tempShare.bat led to cmd crash with application error and exception code 0xc00000fd which means Stack overflow (oddly enough - it stopped at different line if run repeatedly e.g. 10692/10711/10707 so I can't give any exact answer about count limit of lines in parentheses).



Fortunately, no error happens redirecting output from a for loop.



Hence, following slight changes to the original script led to desired effect. Adjusted script parses itself in a simple for /F loop and performs only echo commands between BEGIN CERTIFICATE and END CERTIFICATE inclusively (see lines 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


Output:



d:bat> erase 7za.exe 2>nul

d:bat> D:batSUtempShare.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) …


The following tempShareExitLoop.bat does the same but stops reading itself after reaching the END CERTIFICATE line. Important: insert the :OutCertificate procedure somewhere (immediately) below some goto :eof in your code.



@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





share|improve this answer


























  • Wow amazing thank you

    – Mark Deven
    Jan 10 at 16:59











  • I modified your script so it looks for REM ARandomNumber instead of echo -----BEGIN CERTIFICATE----- so it can have multiple in the same script.

    – Mark Deven
    Jan 11 at 12:36











  • I'm getting an error: ) was unexpected at this time.. Can you take a look at my script and see if I have it right? github.com/ITCMD/ITCMD-STORAGE/blob/master/tempShare.bat

    – Mark Deven
    Jan 11 at 13:31






  • 1





    @MarkDeven Never use :label nor :: label-like comment inside a command block enclosed in () parentheses. Just remove the :break … line and keep set "_out=" instead of ´goto break…´.

    – JosefZ
    Jan 11 at 22:12








  • 1





    @MarkDeven answer updated.

    – JosefZ
    Jan 12 at 23:54











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1392067%2fdoes-batchs-parentheses-have-a-limit-to-how-much-output-it-can-hold%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Indeed, running unadjusted tempShare.bat led to cmd crash with application error and exception code 0xc00000fd which means Stack overflow (oddly enough - it stopped at different line if run repeatedly e.g. 10692/10711/10707 so I can't give any exact answer about count limit of lines in parentheses).



Fortunately, no error happens redirecting output from a for loop.



Hence, following slight changes to the original script led to desired effect. Adjusted script parses itself in a simple for /F loop and performs only echo commands between BEGIN CERTIFICATE and END CERTIFICATE inclusively (see lines 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


Output:



d:bat> erase 7za.exe 2>nul

d:bat> D:batSUtempShare.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) …


The following tempShareExitLoop.bat does the same but stops reading itself after reaching the END CERTIFICATE line. Important: insert the :OutCertificate procedure somewhere (immediately) below some goto :eof in your code.



@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





share|improve this answer


























  • Wow amazing thank you

    – Mark Deven
    Jan 10 at 16:59











  • I modified your script so it looks for REM ARandomNumber instead of echo -----BEGIN CERTIFICATE----- so it can have multiple in the same script.

    – Mark Deven
    Jan 11 at 12:36











  • I'm getting an error: ) was unexpected at this time.. Can you take a look at my script and see if I have it right? github.com/ITCMD/ITCMD-STORAGE/blob/master/tempShare.bat

    – Mark Deven
    Jan 11 at 13:31






  • 1





    @MarkDeven Never use :label nor :: label-like comment inside a command block enclosed in () parentheses. Just remove the :break … line and keep set "_out=" instead of ´goto break…´.

    – JosefZ
    Jan 11 at 22:12








  • 1





    @MarkDeven answer updated.

    – JosefZ
    Jan 12 at 23:54
















1














Indeed, running unadjusted tempShare.bat led to cmd crash with application error and exception code 0xc00000fd which means Stack overflow (oddly enough - it stopped at different line if run repeatedly e.g. 10692/10711/10707 so I can't give any exact answer about count limit of lines in parentheses).



Fortunately, no error happens redirecting output from a for loop.



Hence, following slight changes to the original script led to desired effect. Adjusted script parses itself in a simple for /F loop and performs only echo commands between BEGIN CERTIFICATE and END CERTIFICATE inclusively (see lines 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


Output:



d:bat> erase 7za.exe 2>nul

d:bat> D:batSUtempShare.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) …


The following tempShareExitLoop.bat does the same but stops reading itself after reaching the END CERTIFICATE line. Important: insert the :OutCertificate procedure somewhere (immediately) below some goto :eof in your code.



@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





share|improve this answer


























  • Wow amazing thank you

    – Mark Deven
    Jan 10 at 16:59











  • I modified your script so it looks for REM ARandomNumber instead of echo -----BEGIN CERTIFICATE----- so it can have multiple in the same script.

    – Mark Deven
    Jan 11 at 12:36











  • I'm getting an error: ) was unexpected at this time.. Can you take a look at my script and see if I have it right? github.com/ITCMD/ITCMD-STORAGE/blob/master/tempShare.bat

    – Mark Deven
    Jan 11 at 13:31






  • 1





    @MarkDeven Never use :label nor :: label-like comment inside a command block enclosed in () parentheses. Just remove the :break … line and keep set "_out=" instead of ´goto break…´.

    – JosefZ
    Jan 11 at 22:12








  • 1





    @MarkDeven answer updated.

    – JosefZ
    Jan 12 at 23:54














1












1








1







Indeed, running unadjusted tempShare.bat led to cmd crash with application error and exception code 0xc00000fd which means Stack overflow (oddly enough - it stopped at different line if run repeatedly e.g. 10692/10711/10707 so I can't give any exact answer about count limit of lines in parentheses).



Fortunately, no error happens redirecting output from a for loop.



Hence, following slight changes to the original script led to desired effect. Adjusted script parses itself in a simple for /F loop and performs only echo commands between BEGIN CERTIFICATE and END CERTIFICATE inclusively (see lines 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


Output:



d:bat> erase 7za.exe 2>nul

d:bat> D:batSUtempShare.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) …


The following tempShareExitLoop.bat does the same but stops reading itself after reaching the END CERTIFICATE line. Important: insert the :OutCertificate procedure somewhere (immediately) below some goto :eof in your code.



@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





share|improve this answer















Indeed, running unadjusted tempShare.bat led to cmd crash with application error and exception code 0xc00000fd which means Stack overflow (oddly enough - it stopped at different line if run repeatedly e.g. 10692/10711/10707 so I can't give any exact answer about count limit of lines in parentheses).



Fortunately, no error happens redirecting output from a for loop.



Hence, following slight changes to the original script led to desired effect. Adjusted script parses itself in a simple for /F loop and performs only echo commands between BEGIN CERTIFICATE and END CERTIFICATE inclusively (see lines 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


Output:



d:bat> erase 7za.exe 2>nul

d:bat> D:batSUtempShare.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) …


The following tempShareExitLoop.bat does the same but stops reading itself after reaching the END CERTIFICATE line. Important: insert the :OutCertificate procedure somewhere (immediately) below some goto :eof in your code.



@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






share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 12 at 23:53

























answered Jan 10 at 16:15









JosefZJosefZ

7,25041544




7,25041544













  • Wow amazing thank you

    – Mark Deven
    Jan 10 at 16:59











  • I modified your script so it looks for REM ARandomNumber instead of echo -----BEGIN CERTIFICATE----- so it can have multiple in the same script.

    – Mark Deven
    Jan 11 at 12:36











  • I'm getting an error: ) was unexpected at this time.. Can you take a look at my script and see if I have it right? github.com/ITCMD/ITCMD-STORAGE/blob/master/tempShare.bat

    – Mark Deven
    Jan 11 at 13:31






  • 1





    @MarkDeven Never use :label nor :: label-like comment inside a command block enclosed in () parentheses. Just remove the :break … line and keep set "_out=" instead of ´goto break…´.

    – JosefZ
    Jan 11 at 22:12








  • 1





    @MarkDeven answer updated.

    – JosefZ
    Jan 12 at 23:54



















  • Wow amazing thank you

    – Mark Deven
    Jan 10 at 16:59











  • I modified your script so it looks for REM ARandomNumber instead of echo -----BEGIN CERTIFICATE----- so it can have multiple in the same script.

    – Mark Deven
    Jan 11 at 12:36











  • I'm getting an error: ) was unexpected at this time.. Can you take a look at my script and see if I have it right? github.com/ITCMD/ITCMD-STORAGE/blob/master/tempShare.bat

    – Mark Deven
    Jan 11 at 13:31






  • 1





    @MarkDeven Never use :label nor :: label-like comment inside a command block enclosed in () parentheses. Just remove the :break … line and keep set "_out=" instead of ´goto break…´.

    – JosefZ
    Jan 11 at 22:12








  • 1





    @MarkDeven answer updated.

    – JosefZ
    Jan 12 at 23:54

















Wow amazing thank you

– Mark Deven
Jan 10 at 16:59





Wow amazing thank you

– Mark Deven
Jan 10 at 16:59













I modified your script so it looks for REM ARandomNumber instead of echo -----BEGIN CERTIFICATE----- so it can have multiple in the same script.

– Mark Deven
Jan 11 at 12:36





I modified your script so it looks for REM ARandomNumber instead of echo -----BEGIN CERTIFICATE----- so it can have multiple in the same script.

– Mark Deven
Jan 11 at 12:36













I'm getting an error: ) was unexpected at this time.. Can you take a look at my script and see if I have it right? github.com/ITCMD/ITCMD-STORAGE/blob/master/tempShare.bat

– Mark Deven
Jan 11 at 13:31





I'm getting an error: ) was unexpected at this time.. Can you take a look at my script and see if I have it right? github.com/ITCMD/ITCMD-STORAGE/blob/master/tempShare.bat

– Mark Deven
Jan 11 at 13:31




1




1





@MarkDeven Never use :label nor :: label-like comment inside a command block enclosed in () parentheses. Just remove the :break … line and keep set "_out=" instead of ´goto break…´.

– JosefZ
Jan 11 at 22:12







@MarkDeven Never use :label nor :: label-like comment inside a command block enclosed in () parentheses. Just remove the :break … line and keep set "_out=" instead of ´goto break…´.

– JosefZ
Jan 11 at 22:12






1




1





@MarkDeven answer updated.

– JosefZ
Jan 12 at 23:54





@MarkDeven answer updated.

– JosefZ
Jan 12 at 23:54


















draft saved

draft discarded




















































Thanks for contributing an answer to Super User!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1392067%2fdoes-batchs-parentheses-have-a-limit-to-how-much-output-it-can-hold%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Index of /

Tribalistas

Listed building