This is my first topic post here on this forum, my apologies in advance for any errors on my part about the use of this forum
(and maybe about my bad english as it is not my native language (dutch here)).
I am working on a project where I make use of alternate data streams.
The goal is to develop some sort of object oriented programming mechanism in pure batch.
I have succeeded in doing so by using alternate data streams.
Object instances can be created out of classes and data encapsulation of private and protected methods and properties is provided.
However, when a data stream is redirected to cmd, the Microsoft header information is shown.
It's just a cosmetic issue, but still an annoying one I would like to solve.
The code I use in the project is way too large to put here.
I have created a small working example of the effect I'd like to tackle.
With prompt I can erase Microsoft header information of multiple cmd's, just not the first one.
test.cmd:
Code: Select all
@echo off
REM Delayed expansion is not necessary, it is just used for this example:
setlocal enableDelayedExpansion
REM Any file can be used as container for alternative data streams:
set "adsfile=ads.txt"
REM Set number of alternative data streams to use in example:
set "adscount=3"
for /l %%i in (1,1,%adscount%) do (
REM Write code to alternative data stream:
>%adsfile%:test%%i echo @echo off
REM Prompt can be used to erase Microsoft header information:
>>%adsfile%:test%%i echo prompt $S$E[2A$E[1D$E[K$E[1A$E[K
>>%adsfile%:test%%i echo echo hi from test%%i
if %%i lss %adscount% (
REM Write call to next alternative data stream:
set /a "next=%%i+1"
>>%adsfile%:test%%i echo cmd /d /q ^<".\%adsfile%":test!next!
)
>>%adsfile%:test%%i echo exit /b
)
REM Test by executing first alternative data stream:
cmd /d /q < %adsfile%:test1
pause
endlocal
exit /b
Removing the line containing "prompt $S$E[2A$E[1D$E[K$E[1A$E[K" will result in:{drive}:\{path}>test.cmd
Microsoft Windows [Version 10.0.18362.418]
(c) 2019 Microsoft Corporation. All rights reserved.
{drive}:\{path}>hi from test1
hi from test2
hi from test3
Press any key to continue . . .
So the prompt's erase effect works on multiple cmd's using redirected alternate data streams, just not on the first one.{drive}:\{path}>test.cmd
Microsoft Windows [Version 10.0.18362.418]
(c) 2019 Microsoft Corporation. All rights reserved.
{drive}:\{path}>hi from test1
Microsoft Windows [Version 10.0.18362.418]
(c) 2019 Microsoft Corporation. All rights reserved.
{drive}:\{path}>hi from test2
Microsoft Windows [Version 10.0.18362.418]
(c) 2019 Microsoft Corporation. All rights reserved.
{drive}:\{path}>hi from test3
Press any key to continue . . .
I have tried things like putting "cmd /d /q < %adsfile%:test1" in a separate script.bat and performing "call script.bat", I have tried with cmd /d /c, with start, all to no avail.
The start command is actually not suited here as my project requires to have these cmd's run in the same command session.
Does anyone know how to solve this?
Thanks in advance!
Edit: replaced all alternative with alternate as that is the correct term.