print output to txt file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
medo
Posts: 1
Joined: 06 May 2014 00:05

print output to txt file

#1 Post by medo » 06 May 2014 00:57

Hello there,

I have a batch file "mybatchfile.bat" to check some IP's and websites, and I need to write/print output the result to a .txt file then it close the window when I hit the last Enter key. I've tried it all day, I have WIN 7.

the commands look exactly like this:

Code: Select all

@echo off
echo ^>
echo ping Google
ping www.google.com
echo ===============================
pause
echo ^>
echo open Google URL
start http://www.google.com/
echo ===============================
pause
echo ^>
echo ping Bing
ping www.bing.com
echo ===============================
pause
echo ^>
echo open Bing URL
start http://www.bing.com/
pause
mybatchfile.bat >> output.txt


Thank you in advance.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: print output to txt file

#2 Post by foxidrive » 06 May 2014 02:31

medo wrote:I have a batch file "mybatchfile.bat" to check some IP's and websites, and I need to write/print output the result to a .txt file then it close the window when I hit the last Enter key. I've tried it all day, I have WIN 7.


The usual way to log a session that has keyboard input is by using a TEE filter. Swiss File Kife has one as part of it's features.

pieh-ejdsch
Posts: 257
Joined: 04 Mar 2014 11:14
Location: germany

Re: print output to txt file

#3 Post by pieh-ejdsch » 06 May 2014 06:45

Hi,

i have modified Daves Tee.cmd a time ago. It is not fast but interaktive commands in the log you can read in the cmd-line (command prompt)
empty Lines in promt only displayed as one empty line.
--- No Support for [strg]+[C].

Code: Select all

::batchTee.bat usage: 
:: command >logfile |batchTee LogFile

@echo off
setlocal enabledelayedexpansion

set "LogFile=%~1"
if not exist "%~1" echo File not found. &exit /b 1
set /a FileOpen =0
set "L="
set "N="
set "T=1"
call :canIread <%1
exit /b 0

:canIread
(type nul>>"%LogFile%") 2>nul && set /a FileOpen +=1

echo off
call :readFile
if %FileOpen% gtr 15 exit /b
goto :canIread

:readFile Filename
for /l %%. in (1 1 1000) do (
 set "ln=" 
 set /p "ln="
 if defined ln (echo(!ln!
  set "L="
  set last=!ln!
  if defined T set "T=" &title Lese !Logfile!
 )
 if not defined ln (
  if not defined L (
   echo(
   set /a "FileOpen=0"
   set /a "L=0"
  )
  set /a N+=1,N%%=100
  if !N! equ 99 2>nul (type nul>>"%Logfile%") && (
   set /a "L+=1000"
   if !L! gtr 50000 title !logfile! end &exit
   (title)
  ) || (set T=1
   set /a "L-=1,L%%=100"
   if !L! equ -1    title !Last!
   if !L! equ -50    title Lese !Logfile!
  )
 )
)
Title -- check output -- : !Last!
exit /b


Phil

Post Reply