i think so
how else would it work ?
Would be easiest/reliable method, but not the only one.
You could pipe everything to cmd.exe, although would need to be written in command prompt style, not batch:
C:\>TYPE test.bat
@ECHO OFF
FOR /F "tokens=*" %%i IN (test.bat) DO ECHO.-- %%i
C:\>test.bat
-- @ECHO OFF
-- FOR /F "tokens=*" %%i IN (test.bat) DO ECHO.-- %%i
C:\>TYPE test.bat | CMD /K
C:\>@ECHO OFF
FOR /F "tokens=*" %%i IN (test.bat) DO ECHO.-- %%i
C:\>:: doesn't work, edit
C:\>TYPE test.bat
@ECHO OFF
FOR /F "tokens=*" %i IN (test.bat) DO ECHO.-- %i
C:\>test.bat
i was unexpected at this time.
C:\>TYPE test.bat | CMD /K
C:\>@ECHO OFF
FOR /F "tokens=*" %i IN (test.bat) DO ECHO.-- %i
-- @ECHO OFF
-- FOR /F "tokens=*" %i IN (test.bat) DO ECHO.-- %i
Although labels would become tricky, especially use of :EOF. 20 lines of C code could do this.
You could also turn each newline into an & then run it:
C:\>CMD /C @ECHO OFF&FOR /F "tokens=*" %i IN (test.bat) DO ECHO.-- %i
C:\>ECHO.-- @ECHO OFF
-- @ECHO OFF
C:\>ECHO.-- FOR /F "tokens=*" %i IN (test.bat) DO ECHO.-- %i
-- FOR /F "tokens=*" %i IN (test.bat) DO ECHO.-- %i
Although a simple rem, label, etc.. would break it. Probably many more methods to do this.
Note about piping, that DEFCON video & powershell:
PS C:\> '"HAI"' > my_script.ps1
PS C:\> . .\my_script.ps1
File C:\my_script.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-hel
p about_signing" for more details.
At line:1 char:2
+ . <<<< .\my_script.ps1
+ CategoryInfo : NotSpecified: (:) [], PSSecurityException
+ FullyQualifiedErrorId : RuntimeException
--- from cmd prompt ---
C:\>echo Set-ExecutionPolicy UnRestricted | powershell -NonInteractive -NoProfile -C "$input | % { Invoke-Expression $_ }"
--- back to powershell ---
PS C:\> . .\my_script.ps1
HAI
--- back to cmd prompt ---
C:\>powershell -NonInteractive -NoProfile -C ". .\my_script.ps1"
HAI
That seems kinda fucked up.. and makes "Set-ExecutionPolicy" pointless, if not then << $input | % { Invoke-Expression $_ } >> can eval most things.
batch just got hella powerful on win7, 08r2