home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   alt.msdos.batch      Fun with MS-DOS batch files      42,547 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 41,501 of 42,547   
   T to Konrad   
   Re: How do I read a pipe inside a batch    
   20 Oct 16 11:13:31   
   
   From: T@invalid.invalid   
      
   On 10/19/2016 07:04 AM, Konrad wrote:   
   >   
   > Hi,   
   >   
   > I think you always need a separate program to read multiple lines from   
   > stdin in a for /f loop.   
   > As mentioned before you can use more.exe or eg. findstr.exe /r /c:.* for   
   > that.   
   > When you want to include empty lines for filtering too you could use   
   > sed.exe. Here is an example batch code (call it MyFilter.bat):   
   >   
   >   
   > @echo off   
   > SetLocal EnableDelayedExpansion   
   >   
   > REM sed.exe inserts one '#' char at the start of each line in order to   
   > include empty lines too   
   > for /f "delims=" %%d in ('sed -e "s/.*/#&/g"') do (   
   >   set "_LINE_=%%d"   
   >   REM remove the prviously inserted first '#' char   
   >   set "_LINE_=!_LINE_:~1!"   
   >   
   >   REM ... insert your own filtering code here ...   
   >   
   >   echo.!_LINE_!   
   > )   
   >   
   >   
   > So you can use it like:   
   >   
   > dir | MyFilter.bat   
   >   
   >   
   > Regards Konrad   
   >   
      
      
   Thank you!   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca