2

I am trying to redirect both the standard out and standard error in a Windows batch file to the same file.

However I would like the standard error and user input prompts to be displayed in the console as well.

I tried the following:

Process_SVN_Repos.bat > Process_SVN_Repos.log 2>&1

However this causes the STD ERROR to go to the file (which I want), but does not show up in console and hence I can not input any user required inputs because I don't see any user prompt.

So basically I am trying to:

  1. Redirect all std out to a file.
  2. Redirect all STD ERROR to the same file.
  3. Also show the same STD ERROR on the console.
  4. See the user prompt the application needs in the console and be able to input the user prompt.
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ayusman
  • 8,509
  • 21
  • 79
  • 132

3 Answers3

1

You need a tee command for Windows. Here are few options:

  1. Rob van der woude pure batch solution / ....

  2. Dave Benham's jscript/bat hybrid

  3. Tee by Microsoft - it's part of Unix services for Windows (after installation it's available in the BIN folder and has no exe extension) - For XP/Windows Server 2003 for Windows Vista, Windows 7, Windows 8, Windows Server 2008, and Windows Server 2012.

  4. Command line co uk

  5. UnixUtls

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
npocmaka
  • 55,367
  • 18
  • 148
  • 187
  • thanks. I will try the Unix Utils. The "Tee by Microsoft" actually doesn't have Windows 8 OS in the supported operating systems list. Still can be tried I guess. – Ayusman Aug 25 '14 at 08:19
  • @Ayusman unix subsystem for win7 works also on win8 but it installs really a lot of stuff so getting a single exe or script may be is a better solution. – npocmaka Aug 25 '14 at 08:34
  • 1
    The pure batch solution does not work because it waits for input to be complete before anything is displayed to console. – dbenham Aug 25 '14 at 12:55
  • @dbenham - good point.I will try to implement a tee as jscript/bat... – npocmaka Aug 25 '14 at 12:58
  • 1
    I've already posted a hybrid batch/Jscript tee :) http://stackoverflow.com/a/10719322/1012053 – dbenham Aug 25 '14 at 13:02
0

Windows doesn't have a tee command, so you can't. As Windows includes Unix you could use one of those shells. I don't know if it has tee, but it has 350 utilities.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Noodles
  • 1,981
  • 1
  • 11
  • 4
  • 1
    You could make your own? `Set Inp = WScript.Stdin Set Outp = Wscript.Stdout Do Until Inp.AtEndOfStream Line=Inp.readline outp.writeline Line 'echo out your line to file here. Loop – Noodles Aug 25 '14 at 08:17
  • Set fso = CreateObject("Scripting.FileSystemObject") Set DeskFldr=objShell.Namespace(16) FName=fso.buildpath(DeskFldr.self.path, "Folder Property List.txt") Set ts = fso.OpenTextFile(FName, 8, true) – Noodles Aug 25 '14 at 08:18
  • are you talking about Windows Power shell? – Ayusman Aug 25 '14 at 08:18
  • So write out TS as specified. – Noodles Aug 25 '14 at 08:18
  • No I'm talking vbscript. I've given you two short programs that if you join them will be a TEE command. – Noodles Aug 25 '14 at 08:32
0

If you are using a Unix environment then you can easily use the tee command. But since you are on Windows, it doesn't support you directly. But there are alternatives that you can use.

I have used Wintee for a similar task like yours. I suggest you use that small utility called wtee.exe. If that can't help your task there are other alternatives as well.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131