Redirection to screen and file

Posted on 2004-04-27
Last Modified: 2008-03-03
i need to redirect o/p to the screen and to the file simaltaneously.(DOS)
the reason for this is that i'm running a ftp session and I want it to be captured to a log file. simaltaneously as the program is run i need some input from the user. If i redirect the output to the log file with ">" operator then there is nothing shown on the screen. The dos I use is the one with XP (cmd)

Thanks in advance
Francois Pelletier
Question by:Francois_P
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
LVL 24

Expert Comment

ID: 10928923
You only get one output device. However, at less than real time, if you first write to log file, or temp file, you can then display content of logfile to the screen. In synchronization but not simultaneously, although it should appear just as well to human. With batch file, you can even have the initial proggie write one line of output, then read it in to display on screen, then write it out to a larger file for accumulation of lines if you want. Crude Shorthand:

Echo "a line" > temp
Type temp
Type temp >> log
LVL 67

Expert Comment

ID: 10929033
Hmm- yes, not simultaneous, but close....
Provide a little more detail on this and someone might be able to narrow it down for you.

I'm thinking something like this would generate a narrower range between the output writes though:
for instance, if I want to display a directory of c:\windows\inf:

for /f %%a in ('dir %windir%\inf') do echo %%a >> results.txt
Now, my results.txt file will contain my results, as well as my seeing them on screen...

Accepted Solution

brianadkins earned 500 total points
ID: 10929279

There is a utility called TEE that will redirect to both:

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.


Author Comment

ID: 10929326
But my problem is not related to a DIR command, I use the FTP command and need the user to interact with it, so I need the FTP command to print the output to the screen live while the session is running, but I also need the output to be redirected to a file to log the result of the session.

Expert Comment

ID: 10929379
TEE seems to work fine here.  I am able to perform an interactive FTP session (browse and get files) and all the text is captured in the log file.


Author Comment

ID: 10929396
Thank Brian, but is there a way to do it without installing a utility. Or is this the only way you know?
Thanks in advance for the answer

Expert Comment

ID: 10929577

You don't really need to "install" anything... just treat tee.exe like an external DOS command.  (Just make sure it's in your path and you should be good to go)

There are a lot of extra 'utility' files that are not availble in DOS , but that are great additions to DOS.  Microsoft's ROBOCOPY is another good example.

Others "must-haves" in my opinion:
PSTools (
Unixutils (
NT Resource Kit utiliies
command-line PKZip tools

LVL 67

Expert Comment

ID: 10929595
Francois_P - I used DIR as an example.
Is your FTP session automated using FTP -s:myscript.ftp (example)
If not, then the tool Brian's recommended would be the only option for you...
Otherwise, enclose the ftp commands within the paren in my prior example.

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question