JSI Tip 3242. A better pipe command.


In tips 0501 and 0823, I demostrated the technique of piping both the commands, and the output of a batch file, to a log file.

pipe.bat is a better script. To use it:

pipe <Drive:>\Folder1\logfile.log <Drive:>\Folder2\script.bat \[param1\] \[param2\] ... \[param7\]

 Parameter   D e s c r i p t i o n 
 <Drive:>\Folder1\logfile.log   The full path to the log file. 
 <Drive:>\Folder2\script.bat   The full path to the script 
 \[paramn\]   Up to seven (7) arguments to the script. 

pipe.bat contains:

@echo off
if \{%1\}

\{\} goto syntax if \{%2\}

\{\} goto syntax if not exist %2 goto syntax @echo %0 %2 %3 %4 %5 %6 %7 %8 %9>%1 2>&1 %2 %3 %4 %5 %6 %7 %8 %9 >>%1 2>>&1 goto end :syntax @echo. @echo missing log file and/or batch file. @echo. @echo pipe Drive:\Folder1\logfile.Drive:\Folder2\script.bat \[param1\] \[param2\] ... \[param7\] @echo. :end
Create a simple test script, containing:
@echo on
If \{%1\}

\{\} goto syntax if not exist %1 goto syntax dir %1 goto end :syntax @echo object not found :end

Then type:

pipe d:\logs\pipe.log c:\util\test.bat d:\zzz

The d:\logs\pipe.log file will contain output similar to:

pipe c:\util\test.bat d:\zzz      

C:\>If \{d:\zzz\}  \{\} goto syntax 

C:\>if not exist d:\zzz goto syntax 

C:\>dir d:\zzz 
 Volume in drive D has no label.
 Volume Serial Number is D5C7-1363

 Directory of d:\zzz

12/28/2000  02:47       <DIR>          .
12/28/2000  02:47       <DIR>          ..
10/20/2000  11:45       <DIR>          DROP
12/21/2000  13:39       <DIR>          JSI_NEW
10/20/2000  11:45       <DIR>          sub folder
06/08/1999  15:11                4,537 GetFP.bat
07/03/1999  07:41                  329 GetFP.cmd
06/08/1999  13:19                   38 Rsearch.txt
06/08/1999  16:01                  207 Rsearch1.txt
01/08/2000  10:45                1,116 tip.bat
               5 File(s)          6,227 bytes
               5 Dir(s)   2,910,973,952 bytes free

C:\>goto end
NOTE: See tip 2996 » How do I prevent a command from displaying any output, including any error message?


Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish