Use a TEE filter.
--
Regards,
Mic
There is no direct solution using only Windows native commands and
utilities, but as is so often the case, there are free ports of Unix/
Linux utilities that perform the function. In this case, the tee utility
from the CoreUtils package at
http://gnuwin32.sourceforge.net/packages/coreutils.htm
is the appropriate tool.
Usage: tee [OPTION]... [FILE]...
Copy standard input to each FILE, and also to standard output.
-a, --append append to the given FILEs, do not overwrite
-i, --ignore-interrupts ignore interrupt signals
--help display this help and exit
--version output version information and exit
If a FILE is -, copy again to standard output.
The help switch is --help. not /?
--
Ted Davis (tda...@mst.edu)
i.e.
Batch#1
call Batch#2 > output.txt
call Batch#2
Batch#2
(contains: the original contents of your batch file)
...thus, Batch #2 (your original batch file) is called twice - once to
re-direct it's
output to the text file, and then again so you can see the output on the
screen also!
==
Cheers, Tim Meddick, Peckham, London. :-)
"techman41973" <techma...@yahoo.com> wrote in message
news:441067af-4ddc-47ea...@u9g2000pra.googlegroups.com...
That's a big fail Tim. :)
--
Regards,
Mic
(Batch#1.bat)
@echo off
call Batch#2.bat >output.txt
call Batch#2.bat
(Batch#2.bat)
@echo off
find /i "arrogance" idiots.xml
...create two files called (Batch#1.bat) & (Batch#2.bat) with the contents
above and it bloody well will work!
Obviously some output from programs don't redirect, so it absolutely
depends on the [console] program you are executing from (Batch#2.bat).
However, my example above; works.
==
Cheers, Tim Meddick, Peckham, London. :-)
"foxidrive" <foxi...@gotcha.woohoo.invalid> wrote in message
news:%UIKo.2186$3g....@newsfe05.iad...
Again - obviously - the two batch files are dependant upon a third file
called "idiots.xml" existing, and helpfully containing the word
"arrogance".
But, you could substitute *any* command for the line :
"find /i "arrogance" idiots.xml"
...that accepts re-directed screen output.
> Batch#1
> call Batch#2 > output.txt
> call Batch#2
>
> Batch#2
> (contains: the original contents of your batch file)
>
>
> ....thus, Batch #2 (your original batch file) is called twice - once
> to re-direct it's
> output to the text file, and then again so you can see the output on
> the screen also!
> A Post Script -
>
> Again - obviously - the two batch files are dependant upon a third file
> called "idiots.xml" existing, and helpfully containing the word
> "arrogance".
>
> But, you could substitute *any* command for the line :
>
> "find /i "arrogance" idiots.xml"
>
> ....that accepts re-directed screen output.
>
Dwell on this scenario Tim:
You have a batch file which copies files to another drive, if they don't
exist.
How will your second invocation of the same batch file work in
displaying the information to the screen?
--
Regards,
Mic
> Simply use *two* batch files - "nested"
>
> i.e.
>
> Batch#1
> call Batch#2 > output.txt
> call Batch#2
>
> Batch#2
> (contains: the original contents of your batch file)
>
>
> ...thus, Batch #2 (your original batch file) is called twice - once to
> re-direct it's
> output to the text file, and then again so you can see the output on the
> screen also!
A trivial counterexample:
BATCH2.cmd
dir %temp%
del %temp%\*.*
--
Ted Davis (tda...@mst.edu)
This will do:
Echo OFF
dir c*.* /b > log_file.txt
copy log_file.txt con:
Create your log file using normal re-direct, then copy the log file to
the Console.
> This will do:
>
> Echo OFF
> dir c*.* /b > log_file.txt
> copy log_file.txt con:
>
> Create your log file using normal re-direct, then copy the log file to
> the Console.
The issue with that is that it is not real time - and if you want a Tee
filter then the user is watching the batch file run in some cases.
Here are some solutions from a past discussion on the topic:
:: On 4/09/2010 23:54, I'm_HERE wrote: wali...@gmail.com
@echo off
Set "$h=^^^!!!%%&!><?*|^abc!123"
call :tee $h
pause
goto :eof
:tee
setlocal enabledelayedexpansion
echo !%~1!
echo:!%~1!>>tee.txt
endlocal & goto :eof
--
Regards,
Mic
> This will do:
>
> Echo OFF
> dir c*.* /b > log_file.txt
> copy log_file.txt con:
>
> Create your log file using normal re-direct, then copy the log file to
> the Console.
--
Regards,
Mic
> This will do:
>
> Echo OFF
> dir c*.* /b > log_file.txt
> copy log_file.txt con:
>
> Create your log file using normal re-direct, then copy the log file to
> the Console.
The issue with that is that it is not real time - and if you want a Tee
filter then the user is watching the batch file run in some cases.
Here are some solutions from a past discussion on the topic:
:: On 4/09/2010 23:54, I'm_HERE wrote: wali...@gmail.com
@echo off
Set "$h=^^^!!!%%&!><?*|^abc!123"
call :tee $h
pause
goto :eof
:tee
setlocal enabledelayedexpansion
echo !%~1!
echo:!%~1!>>tee.txt
endlocal & goto :eof
:: by Tom Lavedas
@echo off
> TFILTER.VBS echo. sLogName="Logfile.log" ' default name
>>TFILTER.VBS echo. if WSH.Arguments.Count^>0 then
sLogName=WSH.Arguments(0)
>>TFILTER.VBS echo. with CreateObject("Scripting.FileSystemObject")_
>>TFILTER.VBS echo. .OpenTextFile(sLogName, 8, true)
>>TFILTER.VBS echo. .WriteLine Now
>>TFILTER.VBS echo. Do Until WSH.StdIn.AtEndOfStream
>>TFILTER.VBS echo. str = WSH.StdIn.ReadLine
>>TFILTER.VBS echo. wsh.echo str : .WriteLine str
>>TFILTER.VBS echo. Loop
>>TFILTER.VBS echo. end with ' FSO
(echo === Started ====
copy *.bat "c:\folder" /y
echo ====text here=== )|cscript //nologo TFILTER.VBS MyLogFile.txt
del TFILTER.VBS
:: tee.bat - idea from Joachim Hofmann
:: Syntax: TEE logfilename.log dos_command_to_capture
:: Example: tee logfile.log COPY "c:\myfolder\*.txt" "d:\backup\"
:: tee "My log.log" dir c:\*.sys /b
@ECHO OFF
set logfile="%~1"
if exist %logfile% del %logfile%
set "var=%*"
set "var=%var:*.log =%"
set "var=%var:*.log" =%"
for /F "tokens=1* delims=]" %%a IN (
'%var% 2^>^&1^|find /v /n ""'
) DO (
set /p"=%%b"<nul
echo.
set /p"=%%b"<nul>>%logfile%
echo.>>%logfile%
)
pause
--
Regards,
Mic
Yes, if you use the and symbol...
type launch.bag > log_file.txt & type launch.bag > log_file.txt
What have you been smoking, Filegod? ;)
Seriously, I'm not sure what you thought you were typing.
--
Regards,
Mic
I was not smoking, I was falling asleep
Huh, I thought it would work since this does:
dir & dir>>some.txt
This works:
type 1.txt & type 1.txt >>2.txt
For that matter, how will deleting files go on the second invocation?
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
You are still not getting it.
Tim's two batch method...
call 4hour_backup.bat
call 4hour_backup.bat >> log
is the same thing as this...
call 4hour_backup.bat & call 4hour_backup.bat >> log
So how long will a 4 hour backup take to complete twice?
Yes, indeed though, it is an inescapable fact you have drawn my attention
to.
Not so much the 4-hour-putdown in response to poor old "Filegod",....
But the citation of what would happen on copying files when they don't
exist in the destination ("foxidrive") and your own comment thrown in about
deleting files as well.
Of course my idea of repeating two batch-files will not work if the
conditions cannot be repeated by issuing the same commandline twice in a
row.
But having said that - there must be simply billions of instances when this
solution *would* meet the requirements of the OP.
==
Cheers, Tim Meddick, Peckham, London. :-)
"Todd Vargo" <tlv...@sbcglobal.netz> wrote in message
news:idjuvj$qgs$1...@news.albasani.net...
Oh really?
The directory can be grafted to another directory such as:
ren "program files\some dir" c:\backup
One thing is he never did state the operating system soI wrote it
to make it run DOS 6.22 to Win XP since this is alt.msdos.batch
not alt.msdos.batch.nt, I am looking at the EXACT topic & I have
seen someone else did a reply using (FOR & TOKENS) but if he is using
DOS 6.22 TOKENS would not work, my opinion is that he is running
Win XP.
Trust me Todd, when I did change to XP you were a big help to me
when I was converting over, I think a lot of the old DOS gets
forgotten when folks get away from DOS 6.22-Win9x.
I do consider the Command Interpreter in Win XP the best I did
try yet.
I am waiting to see the OP do a reply since it could be a waste
of my time to just guess what the exact results he wants but I do
think he wants to use use (tokens)(for/f)&(xcopy).
My first ness up was I had the (&) in the batch file without
a space so it ended up as part of the directory name...
I still would like to see you start a web site, I would even
help you by slapping a Perl search engine in there!
No, I have attempted to get you to stop and think for a moment just exactly
why yours and FileGod's suggestions will fail to do what the OP requested
(and ancient FAQ around here).
>
> Yes, indeed though, it is an inescapable fact you have drawn my attention
> to.
>
> Not so much the 4-hour-putdown in response to poor old "Filegod",....
>
> But the citation of what would happen on copying files when they don't
> exist in the destination ("foxidrive") and your own comment thrown in
> about deleting files as well.
>
> Of course my idea of repeating two batch-files will not work if the
> conditions cannot be repeated by issuing the same commandline twice in a
> row.
Good, you have seen the light on this problem then (although not with top
posting).
>
> But having said that - there must be simply billions of instances when
> this solution *would* meet the requirements of the OP.
Only if you know what the batch does prior to attempting to use it. There
are too many more instances where this method could have catostrophic
effects by not knowing what the batch actually does prior to suggesting to
someone without batch knowledge to go ahead and try it.
Sanity check...
Apparently, there are multiple discussions going on in this thread.
Obviously, the original one was to answer the OP's question, which was to
send output of a batch file to a text file as well as to screen at the same
time. This question has been a long time FAQ here. The best possible
solution (a TEE filter) has already been suggested as both a downloadable
binary as well as a VBScript solution.
An attempt (by Tim Meddick) to offer a solution by running the batch twice
by using a second batch which started an obtuse discussion about, how this
is not rocket science, but Tim continued to ignore the fact that running the
same batch twice just to redirect and display the output can cause major
failures. One obvious mode of failure as I pointed out is; if the batch was
intended to delete files, then first invocation will delete the files while
the second invocation will have nothing to display because the files were
already deleted.
Meanwhile in a separate thread, FileGod suggested using the & symbol. An
example was included to use TYPE to send the contents of an arbitrary file
to another file and used the & to repeat the process. Additional attempts to
provide examples in that thread using DIR and then with TYPE again and then
with REN, still oblivious to the original request to send output of a
(complete) batch file to a text file as well as to screen at the same time.
Which brings us to the response above. I don't know how a comparison of REN
to XCOPY or REN by date became part of this discussion (to send output of a
batch file to a text file as well as to screen at the same time) or how they
even remotely relate to it. <shrug>
What would be the point to create yet another website that people wont read
because they don't know the right questions or terminology to input into a
search engine? Prof. Timo already posts a weekly FAQ which leads to his site
which contains links to many existing sites that for whatever reason, people
are just not finding their answers prior to posting.
I will admit that I [probably] don't know half as much as you about the
PC and less than 1/10 of what you know about composing command scripts for
the Window's Command Processor. But there's no excuse for over-confidence
in a rush to put other's down...
I already admitted that you showed me what I SHOULD have known about my
solution NOT being any good for commands that cannot be repeated - like
"delete" and "copy" operations. But I also already said that while I admit
that stupid over-sight, that my "nested two-batch script" solution would be
fine in billions more other cases.
( That is why, incidentally, I suggested it in the first place - because
I employ the "repeat command" in batch scripts so to preview the redirected
results. Or to also save results of a command by repeating it for both
text-file and console output )
You were quite right to correct the major "hole" in my logic that I
thought my suggestion would be sufficient to answer the OP's query, when
clearly, in reality, it was only half a solution! But then, I resent your
apparent attitude that my humility at always giving way to your greater
knowledge is not enough for you, and you are already thinking of the next
crushing comments for me notwithstanding
Please, I just wish. you would give me the benefit of your knowledge
when dissecting my efforts to aid other's - instead of trying to play the
art-critic on my ass.
==
Cheers, Tim Meddick, Peckham, London. :-)
P.S. Of course my solution works as far as it goes (with commands that do
not change the output. i.e. ones that you can repeat twice in the same
script) It's too simple - write the command once, re-directed to text-file,
like the OP wanted, and then next in order to display the same output to
screen. Why would you say it "fails".
"Todd Vargo" <tlv...@sbcglobal.netz> wrote in message
news:idmip2$m9b$2...@news.albasani.net...
> my "nested two-batch script" solution would be fine in billions more
> other cases.
I have given this considerable thought and have concluded that nearly all
such cases are better served by
call batch1 > dump.txt
type dump.txt
The only kinds of batch files that your process even works for are those
that don't actually do anything, just generate reports of static
situations. There is little point in repeating the overhead of
generating the report when the results already exist as a file. In fact,
if the report is of a dynamic situation, then repeating the program
doesn't necessarily generate the same report, so capturing (and
displaying) a single instance of the report is the only way to make the
display and the file match.
I find it helpful, and less embarrassing, when proposing a new algorithm,
to give it quite a bit of deep thought, especially of the limiting cases
and of possible damage it might cause, then to carefully explain the
limits and possible damage. If the algorithm is not already in use,
there may well be a good reason why. If 'the elders' find fault with it,
but don't give carefully thought out and detailed objections, their
reactions my be because it is simply wrong on so many levels that it
would take all day to work out and write the details, but that the
wrongness is clear as a gestalt to those with sufficient experience and
expertise. Your suggestion exhibits that type of wrongness.
--
Ted Davis (tda...@mst.edu)
Right, but watch it or you will be next to be accused of being "too
self-confident and too eager to point out others failings."
Actually, foxydrive pointed it out. I just elaberated on it because he did
not explain and you continued to defend your mistake.
> I resent your apparent attitude that my humility at always giving way to
> your greater knowledge is not enough for you, and you are already thinking
> of the next crushing comments for me notwithstanding
>
> Please, I just wish. you would give me the benefit of your knowledge
> when dissecting my efforts to aid other's - instead of trying to play the
> art-critic on my ass.
I am not here to point out anyones errors. However, when an error is made,
it is important for anyone who spots it to point it out so others reading it
wont falling into the same mistakes. For the record, I am not the one
comparing who knows more, nor do I sit here waiting for you to post just to
respond. If you continue with these personal attacks, I'm sending you back
to the twit filter again.
>
> ==
>
> Cheers, Tim Meddick, Peckham, London. :-)
>
>
> P.S. Of course my solution works as far as it goes (with commands that do
> not change the output. i.e. ones that you can repeat twice in the same
> script) It's too simple - write the command once, re-directed to
> text-file, like the OP wanted, and then next in order to display the same
> output to screen. Why would you say it "fails".
We both know that all you are going to do is dispute what has already been
explained. It's a pointless discussion so let's just agree to disagree and
move on.
But I would straight-away admit any failings of mine, and be grateful of
it.
But also, will always take exception to unwarranted put-downs when people
abandon politeness and common decency.
I think sometimes people here forget that the posts are originating from
actual human-beings!
==
Cheers, Tim Meddick, Peckham, London. :-)
"Todd Vargo" <tlv...@sbcglobal.netz> wrote in message
news:idp8e5$i2e$1...@news.albasani.net...
> But I would straight-away admit any failings of mine, and be grateful of
> it.
Oh yeah?
--
Regards,
Mic
That's only human.
All the best, Timo (aka Perfesser Pundit in news:rec.humor)
--
Prof. Timo Salmi mailto:t...@uwasa.fi ftp & http://garbo.uwasa.fi/
Hpage http://www.uwasa.fi/laskentatoimi/english/personnel/salmitimo/
Department of Accounting and Finance, University of Vaasa, Finland
Perfesser's nauseating puns: ftp://garbo.uwasa.fi/pc/ts/tspun23.zip
I bet if there was a it counter on Timo's sites they would show a large
number of hits, I have no idea how many times I myself have been there
or eve Richard Bonners site, I even ended up on Richard's site today.
I am sure I would not be the only one that would check out your site
if you started one.
Shoot, I need to put some more hit counters on on my site, I will
get back to work on it after I get my main computer back up, I still
have errors on it like one of the search scripts need work, the space
being used by the wallpaper could be used for better stuff such as
source code...
Have a good one Todd.
What do you think about batch-file compilers?
(e.g. BAT2EXEC.COM & BATLITE.EXE)
==
Cheers, Tim Meddick, Peckham, London. :-)
"Timo Salmi" <t...@uwasa.fi> wrote in message
news:4d00f856$0$14455$9b53...@news.fv.fi...
I, among others, consider batch file compiling useless.
All the best, Timo
--
Prof. Timo Salmi mailto:t...@uwasa.fi ftp & http://garbo.uwasa.fi/
Hpage: http://www.uwasa.fi/laskentatoimi/english/personnel/salmitimo/
Department of Accounting and Finance, University of Vaasa, Finland
Useful CMD script tricks http://www.netikka.net/tsneti/info/tscmd.php
Why is he asking this question on this thread?
Ever hear of the term "thread hijacking"? It seems to be his forte.
Unfortunately, hit counters do not tell you what a visitor was actually
looking for, or if they found it. More interesting would be to know if a
poster of a FAQ actually looked on Timo's site when they claim to have done
extensive searching for the past hour (that's laughable). Those posters
almost always are looking for a handout rather than put forth real effort to
learn something about their subject.
I don't know which one of your little friends your weak attempt at trying
to talk down to people as if they're not going to be taking part in a
thread that they posted to, is trying to impress...
You're talking out of your ass when you say I'm known to "hijack" other
people's threads.
If you actually bothered to read back though this thread (if you can't
read, get one of your little friends to read it to you) you'd see that I
have been taking part - then Prof. Timo Salmi posted a comment addressed at
me - to which I responded!
AND THAT IS ALL I DID!
Your an idiot for having a go at me!
I'm normally a quiet guy, and really try to take other's feelings into
account and rarely criticize.
But when some arrogant turd such as you, takes it upon himself to try and
intimidate and bully me, I take exception....
Just keep your bloody nose out of what is none of your business.
==
Cheers, Tim Meddick, Peckham, London. :-)
"Todd Vargo" <tlv...@sbcglobal.netz> wrote in message
news:idsamc$ln$2...@news.albasani.net...
> But when some arrogant turd such as you
I wonder if Tim has looked in the mirror lately?
Who was it that came here and loudly proclaimed that he was going to top
post 'because other groups did it' and ignored the advice to follow the
conventions of the group?
Tim, Tim, Tim.
--
Regards,
Mic
Consider this, Todd:
The people who ask here are the ones who have the wit to ask questions. They
are the ones who are considered in today's world to have researched the
matter....
What has what you just wrote, got to do with anything?
Hypocrisy!
It's not *me* that's "hijacking" anything - but the "thirst" to try and
make some poor bugger (me) bleed that's driving all these "vultures" to
change the subject of topic!
Don't blame me for defending myself!
==
Cheers, Tim Meddick, Peckham, London. :-)
"foxidrive" <foxi...@gotcha.woohoo.invalid> wrote in message
news:xAjMo.7490$Wq1....@newsfe11.iad...
Damn, this is starting to get good from an Aussie point of view! Heh
heh!
Hope you blokes keep it up. Way better entertainment on here in the
past week / fortnight than there is on tele...
A moderated group would have solved the issue before it started. I belong to
a group where if the subject line is not properly formed, it goes into the
bin bucket without notification. Perhaps a prerequisite for posting to amb
could be to require reading Timo's FAQ material and then pass a quiz on it.
;)
==
Tim Meddick, Peckham, London. :-(
"Todd Vargo" <tlv...@sbcglobal.netz> wrote in message
news:idtki8$vnm$1...@news.albasani.net...
I DO APPOLOGISE FOR MY LAGUAGE.....
I do not think there's an excuse for it, and whereas, I know that I have no
obligation to say sorry for it, I do want people to know I regret it.
I let someone get under my skin again, and I really should know better. I
feel he doesn't let go and pursues me for the most trivial of matters which
he builds upon.
It's no exaggeration to say I feel victimised by him and some others seem
to enjoy the same as some category of sport for their amusement.
To Todd V -
Seriously - leave me alone man - you don't see me going after other people,
and you may claim you don't, but here we are again.
Can you simply not resist thinking you must answer my posts?
Do I represent that great a threat to you that you feel you have to answer
every single piece of rhetoric I utter?
Seriously - leave me alone man!
Those are the type that most of the time do not say thanks after
someone does a complete working script, I was very happy to see all
the more stuff added to the command interpreter for Win NT/XP, shoot
I do not even use my old DOS programs anymore I did in Basic, I have
been practicing Basic a little just so I do not forget everything.
Right now I am playing with C++ & getting a collection of source
that works, My batch file for C++ compilers handle 3 compilers so
far.