3

Given a windows .cmd file abc.cmd

abc.cmd > output.log

The above command line operation would save the output of the execution to output.log file.

Are there options for running this command so as to create multiple copies of this log. That is, I want one copy created in one location, and another in a different location.

Please do not ask my to run a copy command. I am looking for command line "options".

Angad
  • 3,389
  • 3
  • 30
  • 40
  • 1
    `copy output.log \path\to\new\location\copy1.log` – Marc B Oct 24 '14 at 19:51
  • 1
    `>` is a redirection operator, not a command, and does not have any options. – admdrew Oct 24 '14 at 19:55
  • @admdrew There are several options for using redirection as could be found here: http://ss64.com/nt/syntax-redirection.html. I am just not entirely sure if multiple redirection is not one of them. – Angad Oct 24 '14 at 20:01
  • 1
    Possible duplicate of [how to redirect a output of a command to two files](http://stackoverflow.com/questions/625571/how-to-redirect-a-output-of-a-command-to-two-files) – Steve Chambers Jan 15 '16 at 11:01

4 Answers4

4

Any Windows implementation of the unix tee command would work perfectly. There are free options out there. I like to use the GNU utilities for Windows, which includes tee.exe.

Usage is simple:

abc.cmd | tee out1.txt >out2.txt

Or, you could write your own implementation of tee using Windows Scripting Host (WSH) - no exe to download! triggeradeadcat attempted to do so, but that implementation is flawed because it uses line based input/output instead of character based. It will not work well if the command has interactive prompts and responses on the same line.

Below is a handy JScript implementation that I have used in many projects. I use hybrid JScript/batch techniques so that the utility can be called directly without having to specify CSCRIPT.

@if (@X)==(@Y) @end /* Harmless hybrid line that begins a JScript comment

::--- Batch section within JScript comment that calls the internal JScript ----
@echo off
cscript //E:JScript //nologo "%~f0" %*
exit /b

----- End of JScript comment, beginning of normal JScript  ------------------*/
var fso = new ActiveXObject("Scripting.FileSystemObject");
var mode=2;
if (WScript.Arguments.Count()==2) {mode=8;}
var out = fso.OpenTextFile(WScript.Arguments(0),mode,true);
var chr;
while( !WScript.StdIn.AtEndOfStream ) {
  chr=WScript.StdIn.Read(1);
  WScript.StdOut.Write(chr);
  out.Write(chr);
}

Again, the usage is simple:

abc.cmd | tee out1.txt >out2.txt
Community
  • 1
  • 1
dbenham
  • 127,446
  • 28
  • 251
  • 390
2

No there is no such command line options present as already commented by others but you can run the command multiple times redirecting them to different files like below

date > D:\Testing\test.log & date > D:\Testing\test1.log

So in your case it would be like

abc.cmd > output.log & abc.cmd > output1.log
Rahul
  • 76,197
  • 13
  • 71
  • 125
  • Can you guarantee that each run of abc.cmd yields the same result? This just seems like a bad idea to me. Perhaps this can be used in some circumstances, but in general it is no good. Also, I see no advantage of this over simply using COPY to replicate the output file. – dbenham Oct 25 '14 at 13:34
0

From the site you posted:

command > fileA > fileB - Redirect output to separate files.

Is that not what you're looking for?

Brady
  • 403
  • 1
  • 8
  • 19
0
Set Inp = WScript.Stdin
Set Outp = Wscript.Stdout
Set fso = CreateObject("Scripting.FileSystemObject")
Set file = fso.CreateTextFile(wscript.Arguments(0), vbtrue)
        Do Until Inp.AtEndOfStream
            Line=Inp.readline
            outp.writeline Line
            file.writeline Line
        Loop

Haven't tested.

dir |cscript tee.vbs filename1.txt > filename2.txt
  • Good idea, but you should not use line based IO - it does not work well with programs that prompt for input. Also, you can use hybrid scripting to make it easier to call. See [my answer](http://stackoverflow.com/a/26563182/1012053) – dbenham Oct 25 '14 at 13:58