In Bash, I can do something like this
somecmd << END a lot of text here END to feed input to a command directly from a script. I need to do the same in CMD.exe batch files (.cmd scripts). Is it possible?
13 Answers
I believe you can use a single ^ character for each line.
EG:
echo This is a really long ^ text message that spans multiple ^ lines returns:
C:\Users\Jonno>echo This is a really long ^ More? text message that spans multiple ^ More? lines This is a really long text message that spans multiple lines 4It's simple, but not as clean looking as it is in Unix/Linux. Try this:
(@echo.a lot of @echo.text here ) | somecmd Note that the . after the echo statement allows you to begin a line with blanks. The @ symbol is needed to prevent the echo statement from being sent to somecmd. You can eliminate the @ symbol thusly:
echo off (echo.a lot of echo.text here ) | somecmd echo on 4Until now, I don't have found any solution to this problem !
I have only a workaround in defining some BAT scripts.
Using my script, the solution to your problem look like this
call INIT-TRAMEX.bat %assign-sysout% FILE.SYSOUT.TXT %w% a lot of %w% text here somecmd <%sysout% But in all cases, the direct indirection is impossible.
INIT-TRAMEX.bat file defines %ASSIGN-SYSOUT% and %W% variables
::****************************************************************************** ::* INIT-TRAMEX.bat ::****************************************************************************** @echo OFF set scriptdir=c:\Scripts set ASSIGN-SYSOUT=call %scriptdir%\AssignSysout.bat set WRITE-TEXT=call %scriptdir%\WriteText.bat set W=call %scriptdir%\WriteText.bat ASSIGN-SYSOUT script defines %sysout% variable and create an empty file. It contains following lines
set sysout=%1 @echo.>%sysout% del %sysout% WRITE-TEXT script contains following lines
IF "%1"=="" goto line echo %* >>%sysout% goto quit :line echo. >>%sysout% :quit Using this tips, DOS script is more readable.