#1 02 Nov 2011 17:02

biatche
Member
Registered: 01 Nov 2011
Posts: 14

[help] echo to screen and file in a single line

is it possible to

echo hello world > screen(like normal) & helloworld.txt?

Offline

#2 03 Nov 2011 07:47

jeb
Member
From: Germany
Registered: 19 Nov 2010
Posts: 99

Re: [help] echo to screen and file in a single line

Normally you need an external tee command for this, but if you only need it for one line at a time, you can write your own tee with batch.

@ECHO OFF
rem *** singleLineTee.bat destination1 [destination2]
rem *** If you only use one destination the second dest is stdout
setlocal EnableDelayedExpansion
set /p var=
> "%~1" echo(!var!
if "%~2"=="" (
  echo(!var!
) ELSE (
  > "%~2" echo(!var!
)

To use it

echo hello | singleLineTee myFile.txt
echo world | singleLineTee myFile.txt secondFile.txt

Offline

#3 03 Nov 2011 09:24

jumper
Member
From: tunisia, Mornaguia
Registered: 17 Apr 2009
Posts: 54
Website

Re: [help] echo to screen and file in a single line

@echo off
::  echo hello world | teeCmd 1.txt 
::  dir | teeCmd 1.txt 2.txt 3.txt ... 6.txt
::
for /f "delims=" %%z in ('more') do (
 for %%a in (con %1 %2 %3 %4 %5 %6) do >>%%a echo(%%z
)

Offline

#4 03 Nov 2011 09:33

jeb
Member
From: Germany
Registered: 19 Nov 2010
Posts: 99

Re: [help] echo to screen and file in a single line

@Jumper: Nice extension smile

Offline

Board footer

Powered by FluxBB