Help me to redirect to a file any errors from my batch.
#1
Posted 04 March 2006 - 04:00 PM
Irrelevant: Is it possible to disable the press F6 and F2 messages from my unattended CD? I have all the necessary drivers and I would like to reduce the text mode portion by 10 seconds. Thank you.
#3
Posted 04 March 2006 - 05:00 PM
Example This Checks For C:\Test.txt then copies it top D:\Test.txt
This script reports if it was successful or not successfull.
Quote
Const OverwriteExisting = TRUE
Dim Fso,Act,Report_Log,Ts
Set Fso = CreateObject("Scripting.FileSystemObject")
Set Act = CreateObject("Wscript.Shell")
Report_Log = Act.ExpandEnvironmentStrings("%Systemdrive%\Report_UaInstall.log")
'''' OPEN THE REPORT_UAINSTALL.LOG
Set Ts = Fso.CreateTextFile(Report_Log)
Ts.WriteLine Now() & Space(5) & Act.ExpandEnvironmentStrings("%Username%") & vbCrLf & "Preparing To Copy C:\Test.txt To D:\"
If Fso.FileExists("C:\Test.txt") Then
Fso.CopyFile "C:\Test.txt" , "D:\" , OverwriteExisting
Ts.WriteLine "Confirm Copy Completed"
Else
Ts.WriteLine "Copy File Error" & vbTab & "C:\Test.txt" & vbTab & "Was Not Found"
End If
Ts.Close
If you want help with the vbs script post the cmd script and I will try and do it so they both work together.
#4
Posted 04 March 2006 - 06:02 PM
As for the .vbs, I am a new scripter and I don't know this language. So I prefer to keep things simple and use some standard commands and methods. The only .vbs I have made is for closing some windows which opens at the end of some silent installations (AppActivate, SendKeys etc). But if you want to explain me the logic of your method it is welcome.
#5
Posted 04 March 2006 - 06:19 PM
Just run this with out editing and on your desktop look for this file R1TestLog.txt
I just prefer using VBS is all.
Quote
:: REMOVE THE :: IF YOU ARE INSTALLING FROM A CD OR DVD DRIVE
::for %%i in (C: D: E: F: G: H: I: J: K: L: M: N: O: P: Q: R: S: T: U: V: W: X: Y: Z:) do if exist %%i\SETUP.exe set CDROM=%%i
set P2=Ping -n 2 127.0.0.1
set P3=Ping -n 3 127.0.0.1
set P4=Ping -n 4 127.0.0.1
::REMOVE THE :: IF YOU ARE INSTALLING FROM A CD OR DVD DRIVE
::set TEST=%cdrom%\Apps
:: ADD :: IF TO THE BELOW LINE IF YOU ARE INSTALLING FROM CD OR DVD DRIVE
set TEST=%Systemdrive%\Apps
set TEST1=%TEST%\Cleanup.cmd
set TEST2=%TEST%\ACEMCP591\ACEMCP591PRO.EXE
set TEST3=%TEST%\Alcohol\AlcoholInstall.cmd
set TEST4=%TEST%\Flash\FlsPlyr7Install.cmd
set TEST5=%TEST%\Winamp\WinAmpInstall.cmd
set Name1=Cleanup.cmd
set Name2=AcePro591Install.cmd
set Name3=AlcoholInstall.cmd
set Name4=FlsPlyr7Install.cmd
set Name5=WinAmpInstall.cmd
set TESTLOG="%UserProfile%\DESKTOP\R1TestLog.txt"
::Set M=Missing-^>
Set Proc=Processing..
Set Line=:------------------------------------------------------------------:
for /f "Tokens=*" %%i in ('time /t') do set TIMET=%%i
for /f "Tokens=*" %%i in ('date /t') do set DATET=%%i
for /f "Tokens=*" %%i in ('ver') do set V=%%i
TITLE START CHECK 1
cls && Color f1
%P3%>nul | Echo Preparing Test Your RunOnceEx.cmd
::::::::::::::::CHECK FOR FILE 001 IN YOUR RUNONCE
TITLE CHECK %TEST1%
CLS && COLOR F9
:CHECK1
If Exist %TEST1% Echo %Proc% %Name1% && %P3%>nul && Goto :Next1B
If Not Exist %TEST1% %Proc% %Name1% && %P3%>nul && Goto :Missing1
:Missing1
TITLE Missing %Name1%
CLS && COLOR FC
::If Exist %TESTLOG% Del /s /q %TESTLOG%
echo.
echo %Line% > %TESTLOG%
echo %Line% >> %TESTLOG%
echo %datet% %timet% : %Name1% Is Missing...!!! >> %TESTLOG%
echo Windows Version : %V% >> %TESTLOG%
echo %Line% >> %TESTLOG%
Echo -^> This File : %Name1% Is Missing...!!! && %P3%>nul && goto :Next1a
goto EOF
:Next1a
TITLE Failed %Name1%
CLS && COLOR 2F
echo.
Echo -^> %Name1% Failed Preparing Check %Name2% && %P3%>nul && GOTO :CHECK2
goto EOF
:Next1b
TITLE Passed %Name1%
CLS && COLOR 3F
::If Exist %TESTLOG% Del /s /q %TESTLOG%
echo.
echo %Line% > %TESTLOG%
echo %Line% >> %TESTLOG%
echo %datet% %timet% : %Name1% Has Passed....!! >> %TESTLOG%
echo Windows Version : %V% >> %TESTLOG%
echo %Line% >> %TESTLOG%
Echo This File : %Name1% Has Passed....!! && %P3%>nul && GOTO :CHECK2
goto EOF
::::::::::::::::CHECK FOR FILE 001 IN YOUR RUNONCE
::::::::::::::::CHECK FOR FILE 002 IN YOUR RUNONCE
:CHECK2
TITLE CHECK %TEST2%
CLS && COLOR 4F
if Exist %TEST2% echo %Proc% %Name2% && %P3%>nul && Goto Next2
If not Exist %TEST2% Echo %Proc% %Name2% && %P3%>nul && Goto Missing2
:Next2
TITLE Passed %Name2%
CLS && COLOR 6F
echo.
echo %Line% >> %TESTLOG%
echo %datet% %timet% : %Name2% Has Passed....!! >> %TESTLOG%
echo Windows Version : %V% >> %TESTLOG%
echo %Line% >> %TESTLOG%
Echo This File : %Name2% Has Passed....!! && %P3%>nul && goto :CHECK3
goto EOF
:Missing2
TITLE Missing %Name2%
CLS && COLOR FC
echo.
echo %Line% >> %TESTLOG%
echo %datet% %timet% : %Name2% Is Missing...!!! >> %TESTLOG%
echo Windows Version : %V% >> %TESTLOG%
echo %Line% >> %TESTLOG%
Echo -^> This File : %Name2% Is Missing...!!! && %P2%>nul && goto :Next2a
goto EOF
:Next2a
TITLE Failed %Name2%
CLS && COLOR 2F
echo.
Echo -^> %Name2% Failed Preparing Check %Name3% && %P3%>nul && GOTO :CHECK3
goto EOF
::::::::::::::::CHECK FOR FILE 002 IN YOUR RUNONCE
::::::::::::::::CHECK FOR FILE 003 IN YOUR RUNONCE
:CHECK3
TITLE CHECK %TEST3%
CLS && COLOR 5F
if Exist %TEST3% echo %Proc% %Name3% && %P3%>nul && Goto :Next3
If not Exist %TEST3% Echo %Proc% %Name3% && %P3%>nul && Goto :Missing3
:Next3
TITLE Passed %Name3%
CLS && COLOR 6F
echo.
echo %Line% >> %TESTLOG%
echo %datet% %timet% : %Name3% Has Passed....!! >> %TESTLOG%
echo Windows Version : %V% >> %TESTLOG%
echo %Line% >> %TESTLOG%
Echo This File : %Name3% Has Passed....!! && %P3%>nul && goto :CHECK4
goto EOF
:Missing3
TITLE Missing %Name3%
CLS && COLOR FC
echo.
echo %Line% >> %TESTLOG%
echo %datet% %timet% : %Name3% Is Missing...!!! >> %TESTLOG%
echo Windows Version : %V% >> %TESTLOG%
echo %Line% >> %TESTLOG%
Echo The %Name3% Is Missing...!!! && %P3%>nul && goto :Next3a
goto EOF
:Next3a
TITLE Failed %Name3%
CLS && COLOR 2F
echo.
Echo -^> %Name3% Failed Preparing Check %Name4% && %P3%>nul && GOTO :CHECK4
goto EOF
::::::::::::::::CHECK FOR FILE 003 IN YOUR RUNONCE
::::::::::::::::CHECK FOR FILE 004 IN YOUR RUNONCE
:CHECK4
TITLE CHECK %TEST4%
CLS && COLOR 5F
if Exist %TEST4% echo %Proc% %Name4% && %P3%>nul && Goto Next4
If not Exist %TEST4% Echo %Proc% %Name4% && %P3%>nul && Goto Missing4
:Next4
TITLE Passed %Name4%
CLS && COLOR 6F
echo.
echo %Line% >> %TESTLOG%
echo %datet% %timet% : %Name4% Has Passed....!! >> %TESTLOG%
echo Windows Version : %V% >> %TESTLOG%
echo %Line% >> %TESTLOG%
Echo This File : %Name4% Has Passed....!! && %P3%>nul && goto CHECK5
goto EOF
:Missing4
TITLE Missing %Name4%
CLS && COLOR FC
echo.
echo %Line% >> %TESTLOG%
echo %datet% %timet% : %Name4% Is Missing...!!! >> %TESTLOG%
echo Windows Version : %V% >> %TESTLOG%
echo %Line% >> %TESTLOG%
Echo The %Name4% Is Missing!!!! && %P3%>nul && goto :Next4a
goto EOF
:Next4a
TITLE Failed %Name4%
CLS && COLOR 2F
echo.
Echo -^> %Name4% Failed Preparing Check %Name5% && %P3%>nul && GOTO :CHECK5
goto EOF
::::::::::::::::CHECK FOR FILE 004 IN YOUR RUNONCE
::::::::::::::::CHECK FOR FILE 005 IN YOUR RUNONCE
:CHECK5
TITLE CHECK %TEST5%
CLS && COLOR 5F
if Exist %TEST5% echo %Proc% %Name5% && %P3%>nul && Goto Next5
If not Exist %TEST5% Echo %Proc% %Name5% && %P3%>nul && Goto Missing5
:Next5
TITLE Passed %Name5%
CLS && COLOR 6F
echo.
echo %Line% >> %TESTLOG%
echo %datet% %timet% : %Name5% Has Passed....!! >> %TESTLOG%
echo Windows Version : %V% >> %TESTLOG%
echo %Line% >> %TESTLOG%
echo %Line% >> %TESTLOG%
Echo This File : %Name5% Has Passed....!! && %P3%>nul && goto quit
goto EOF
:Missing5
TITLE Missing %Name5%
CLS && COLOR FC
echo.
echo %Line% >> %TESTLOG%
echo %datet% %timet% : %Name5% Is Missing...!!! >> %TESTLOG%
echo Windows Version : %V% >> %TESTLOG%
echo %Line% >> %TESTLOG%
echo %Line% >> %TESTLOG%
Echo The %Name5% Is Missing!!!! && %P3%>nul && goto :Next5a
goto EOF
:Next5a
TITLE Failed %Name4%
CLS && COLOR 2F
echo.
Echo -^> %Name4% Failed Preparing Check %Name5% && %P3%>nul && GOTO :quit
goto EOF
::::::::::::::::CHECK FOR FILE 005 IN YOUR RUNONCE
:quit
TITLE Gsm Good Bye!
CLS && COLOR F1
echo.
Echo Gsm RunOnceEx Test Completed && %P4%>nul
exit
The logic is I could make a far smaller script then the above.
VBS Script of the same cmd file
Quote
Dim Act, ChkCmd, Dtop, Fso, Line,Report_R1, SD, strChkCmd, Ts
Set Act = CreateObject("Wscript.Shell")
Set Fso = CreateObject("Scripting.FileSystemObject")
SD = Act.ExpandEnvironmentStrings("%Systemdrive%\Apps")
Dtop = Act.SpecialFolders("Desktop")
Report_R1 = Dtop & "\R1_Instal.log"
Line = Chr(171) & " ---------------------------------- " & Chr(187)
Set Ts = Fso.OpenTextFile(Report_R1,2,True)
ChkCmd = Array(SD & "\ACEMCP591\ACEMCP591PRO.EXE",SD & "\Alcohol\AlcoholInstall.cmd",_
SD & "\Cleanup.cmd",SD & "\Flash\FlsPlyr7Install.cmd",SD & "\Winamp\WinAmpInstall.cmd")
For Each strChkCmd In ChkCmd
If Fso.FileExists(strChkCmd)Then
Act.Popup "Confirm File" & vbCrLf & strChkCmd,3,"Confirm", 0 + 32
Ts.WriteLine "Confirm This File Was There" & vbCrLf & strChkCmd & vbCrLf & "Install Started At : " & Now() & vbCrLf & Line
'''' UNCOMMENT THE BELOW LINE TO MAKE ACTIVE
'' Act.Run(strChkCmd),1,True
Else
Act.Popup "Error Missing File" & vbCrLf & strChkCmd,3,"Missing", 0 + 32
Ts.WriteLine "Cannot find This File" & vbCrLf & strChkCmd & vbCrLf & "Error Time And Date : " & Now() & vbCrLf & Line
End If
Next
Ts.Close
Act.Run(Chr(34) & Report_R1 & Chr(34)),1,False
This post has been edited by gunsmokingman: 04 March 2006 - 06:43 PM
#6
Posted 05 March 2006 - 09:55 AM
Quote
Quote
Will APPEND to the contents of mylog.txt the output of the command somebat.cmd, i.e. if the somebat.cmd has multiple output and the last one is an empty line, the resulting mylog.txt will be a log of all outputs + an empty line.
What you need to log is "standard output", NOT "standard error":
http://www.robvander...edirection.html
jaclaz
This post has been edited by jaclaz: 06 March 2008 - 12:31 PM
#7
Posted 06 March 2006 - 02:02 AM
What is really strange is this: When I was making some tests from the run box with the command "test.cmd 2>Errors.log", I was using a copy command in it to copy a non-existent file. Despite the 2> operator, the created error "The system cannot find the file specified" was displaying to the command prompt window and not to the destination file (errors.log), which was empty. When I decided to add more errors in my test.cmd ("ech Hi all" and "del C:\yo.rm"), I ascertained that these error messages was not being displayed in the prompt but in the errors.log ('ech' is not recognized as an internal or external command, operable program or batch file. Could Not Find C:\yo.rm). So I understood that my syntax was correct, the file was being created and it was recording the errors normally, except from the error with the copy command. This screw-up made me to post here and now I know that Jbm's reply was correct. As I said, during the first logon at my real windows setup, the command worked great and redirected the standard error stream to the Errors.log file. Under those circumstances, the error message "The system cannot find the file specified" is normally being logged in my log file. I can't understand why it's not the same from the run box.
#8
Posted 06 March 2006 - 02:44 AM
I can copy what the guy below me has written without error, however since he hasn't written anything yet, I am not given the opportunity to do so, it is not my copying that therefore has an error.
As the message stated, it cannot find the file, it is the finding which is the problem not the copying. This leads me to an obvious response, fix your coding to prevent these eventualities first.
IF EXIST "E:\To Be Copied\A File.ext" COPY "E:\To Be Copied\A File.ext" "G:\Somewhere Else"2>NUL<Edit>
I have used NUL, whereas you would obviously use your chosen file, and possibly, depending upon your requirements, append, (>>).
</Edit>
This post has been edited by Yzöwl: 06 March 2006 - 08:59 AM
#9
Posted 06 March 2006 - 07:14 AM
Yzöwl said:
Yes, that's what I meant.....
...just an idea, but you could use a TEE external command:
http://www.robvanderwoude.com/tee.html
http://www.kilowatts...om/PoofPage.htm
http://gnuwin32.sour...s/coreutils.htm
jaclaz
#10
Posted 06 March 2006 - 06:51 PM
@echo off
dir F:\ ¦ tee -a C:\mylog.log
sleep 5
EXIT
Yzowl, I understood that when the system cannot find a file to copy (or whatever), it's not a stderr but a stdout. That's why when I run my test.cmd from run box I see this message in the command prompt and not in the log. But why during the execution of my script (GuiRunOnce) these messages were being logged in my errors.log? I had 3 lines with the error "The system cannot find the file specified". Also, what I gain if I use the "if exist" command? I tried it and find out that the message "The system cannot find the file specified" is not displayed anywhere. The good point whould be to have a log entry: "The file E:\To Be Copied\A File.ext doesn't exist". So I would know that I have to put that file there. If I use this method, I won't even know about any errors. Here is my test.cmd:
@echo off
Echo ready for the step one.
if exist "C:\yo.rm" COPY "C:\yo.rm" "F:\" 2>errors.log
sleep 5
EXIT
#11
Posted 06 March 2006 - 07:17 PM
#12
Posted 08 March 2006 - 01:03 AM
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run ("%systemdrive%\Alcohol195.exe")
WScript.Sleep 8000
WshShell.SendKeys "{DOWN}"
WScript.Sleep 300
WshShell.SendKeys "{TAB}"
WScript.Sleep 300
WshShell.SendKeys "{ENTER}"
WScript.Sleep 300
WshShell.SendKeys "{TAB}"
WScript.Sleep 300
WshShell.SendKeys " "
WScript.Sleep 300
WshShell.SendKeys "{TAB}"
WScript.Sleep 300
WshShell.SendKeys "{TAB}"
WScript.Sleep 300
WshShell.SendKeys "{TAB}"
WScript.Sleep 300
WshShell.SendKeys "{ENTER}"
WScript.Sleep 2000
WshShell.SendKeys "{ENTER}"
WScript.Quit
The strange is that if I use the WshShell.Run ("Alcohol195.exe") command from the HDD (both .exe and .vbs in C:\), it starts the installation normally. Can you help me? Maybe this is the correct syntax: WshShell.Run (".\Alcohol195.exe")? Is there any way to convert the following code to .vbs, so I can use the %cdrom% variable in the .vbs and give a full path? Thanks.
set tagfile=\WIN51
for %%i in (c d e f g h) do if exist "%%i:%tagfile%" set cdrom=%%i:
#13
Posted 08 March 2006 - 03:58 AM
Checks to see if if CD or DVD drive
Checks to see if the CD or DVD has something in it
Then it checks for this file
"CD_DVD_DRIVE:\Apps\Alcohol120\setup.msi"
Then it start the install
If it cannot find the file then it waits for you to place the correct Disk in the drive. It will loop 6 times for a total of 60 seconds. Then it self closes. This script can be ran from any where on the local computer.
Save as InstallAlcohol120.vbs
To edit this vbs script
":\Apps\Alcohol120\setup.msi" change this color text to what you need
this change the file it looks for.
" /qb /norestart" and change this to what you need
Quote
Set Act = CreateObject("Wscript.shell")
Set Fso = CreateObject("Scripting.FileSystemObject")
Cmd1 = ":\Apps\Alcohol120\setup.msi"
Alcohol120
Function Alcohol120
Do
CT = CT + 1
Set Drv = Fso.Drives
For Each strDrive In Drv
If strDrive.DriveType = 4 Then
If strDrive.IsReady = True Then
If Fso.FileExists(strDrive.DriveLetter & Cmd1) Then
Act.Run(strDrive.DriveLetter & Cmd1 & " /qb /norestart"),1,True : WScript.Quit
End If
Else
If strDrive.IsReady = False Then
ZZ1 = Act.Popup ("The CD Or DVD Does Not Appear Ready" & vbCrLf & strDrive.DriveLetter & ":\" &_
vbCrLf & "Ok to contiue" & vbTab & "Cancel to quit", 10,"Continue Or Quit : " & CT, 5 + 48)
If ZZ1 = vbretry Then : End If
If ZZ1 = vbcancel Then : WScript.Quit : End If
If ZZ1 = -1 Then : End If
If CT = 6 Then : Act.Popup "The defualt time occur preparing to stop script", 5,"Time out Error", 0 + 32 : WScript.Quit : End If
End If
End If
End If
Next
Loop Until CT = 6
End Function
I use alcolhol 120 and I use the msi instaed of the exe
This post has been edited by gunsmokingman: 08 March 2006 - 04:01 AM
#14
Posted 08 March 2006 - 05:20 AM
har-vas, on Mar 8 2006, 05:03 PM, said:
The strange is that if I use the WshShell.Run ("Alcohol195.exe") command from the HDD (both .exe and .vbs in C:\), it starts the installation normally.
If you manually start a VBS from where it is, then it's working directory is where it is. Executing from the registry, usually means that the systemdrive is the working directory, so it is not strange for your script to fail.
This is what I would try
Set WshShell = WScript.CreateObject("WScript.Shell")
Dim ScriptFullPath
ScriptFullPath = Replace(WScript.ScriptFullName, WScript.ScriptName, "")
if WshShell.CurrentDirectory <> ScriptFullPath Then
WshShell.CurrentDirectory = ScriptFullPath
end if
WshShell.Run ("Alcohol195.exe")
WScript.Sleep 8000
WshShell.SendKeys "{DOWN}"
WScript.Sleep 300
WshShell.SendKeys "{TAB}"
WScript.Sleep 300
WshShell.SendKeys "{ENTER}"
WScript.Sleep 300
WshShell.SendKeys "{TAB}"
WScript.Sleep 300
WshShell.SendKeys " "
WScript.Sleep 300
WshShell.SendKeys "{TAB}"
WScript.Sleep 300
WshShell.SendKeys "{TAB}"
WScript.Sleep 300
WshShell.SendKeys "{TAB}"
WScript.Sleep 300
WshShell.SendKeys "{ENTER}"
WScript.Sleep 2000
WshShell.SendKeys "{ENTER}"
WScript.Quit
#15
Posted 08 March 2006 - 09:06 AM
Try using this other version of tee:
http://www.csc.calpo...e/console.shtml
http://www.csc.calpoly.edu/~bfriesen/softw...files/tee32.zip
Quote
Usage:
<command> | tee <filename> [/A]Splits output such that it goes to both <filename> and the screen.
/A appends to the file
This is the one I use, in the other post I forgot to put the link to it...
jaclaz
#16
Posted 08 March 2006 - 10:38 AM
Quote
If strDrive.IsReady = True Then
Quote
If strDrive.DriveType = 4 Then
Quote
If Fso.FileExists(strDrive.DriveLetter & Cmd1) Then
Quote
strDrive.DriveLetter
Act.Run(strDrive.DriveLetter & Cmd1 & " /qb /norestart"),1,True
The script will only work if that statement is true, this is better then using a send key method as this is not the best method to do this.
Now if I took out the first 2 if statements then it would search for strDrive.DriveLetter & Cmd1 on your floppy drive, harddrive, cd or dvd drive. This builds the completed path to the file,
which the action uses.
This post has been edited by gunsmokingman: 08 March 2006 - 10:40 AM
#17
Posted 08 March 2006 - 10:54 AM
Set StdIn = WScript.StdIn
Set StdOut = WScript.StdOut
Set Args=WScript.Arguments
LogFile=Args(0)
Set fso = CreateObject("Scripting.FileSystemObject")
Set LogFile= fso.CreateTextFile(Args(0))
Do While Not StdIn.AtEndOfStream
str = StdIn.ReadLine
StdOut.WriteLine str
LogFile.WriteLine str
Loop
LogFile.Close
Run your Batch file with a pipe to the filter executed with CSCRIPT and add the logfile name you require as a parameter.Something like this:
MyBatchFile.cmd |cscript//nologo TFILTER.VBS MyLogFile.txt
The output of the Batch file is displayed line-by-line and simultaneously captured to MyLogFile.txt line-by-line.
If you change the VBS line:
LogFile.WriteLine strto
LogFile.WriteLine "Line " & (StdIn.Line - 1) & ": " & strthis will number all the lines in the log (but not on screen).
Note: You must execute the TFILTER.VBS with CSCRIPT and not WSCRIPT, (STDIN and STDOUT are not available via WSCRIPT).
#18
Posted 08 March 2006 - 12:57 PM
Yzöwl said:
Yep, but it is also possible by using a "pure" .BAT, see my previously posted link:
http://www.robvanderwoude.com/tee.html
Quote
@ECHO OFF
:: Check Windows version
IF NOT "%OS%"=="Windows_NT" GOTO Syntax
:: Keep variables local
SETLOCAL
:: Check command line arguments
SET Append=0
IF /I [%1]==[-a] (
SET Append=1
SHIFT
)
IF [%1]==[] GOTO Syntax
IF NOT [%2]==[] GOTO Syntax
:: Test for invalid wildcards
SET Counter=0
FOR /F %%A IN ('DIR /A /B %1 2^>NUL') DO CALL :Count "%%~fA"
IF %Counter% GTR 1 (
SET Counter=
GOTO Syntax
)
:: A valid filename seems to have been specified
SET File=%1
:: Check if a directory with the specified name exists
DIR /AD %File% >NUL 2>NUL
IF NOT ERRORLEVEL 1 (
SET File=
GOTO Syntax
)
:: Specify /Y switch for Windows 2000 / XP COPY command
SET Y=
VER ¦ FIND "Windows NT" > NUL
IF ERRORLEVEL 1 SET Y=/Y
:: Flush existing file or create new one if -a wasn't specified
IF %Append%==0 (COPY %Y% NUL %File% > NUL 2>&1)
:: Actual TEE
FOR /F "tokens=1* delims=]" %%A IN ('FIND /N /V ""') DO (
> CON ECHO.%%B
>> %File% ECHO.%%B
)
:: Done
ENDLOCAL
GOTO:EOF
:Count
SET /A Counter += 1
SET File=%1
GOTO:EOF
:Syntax
ECHO.
ECHO Tee.bat, Version 2.10 for Windows NT 4 / 2000 / XP
ECHO Display text on screen and redirect it to a file simultaneously
ECHO.
ECHO Usage: some_command ³ TEE.BAT [ -a ] filename
ECHO.
ECHO Where: "some_command" is the command whose output should be redirected
ECHO "filename" is the file the output should be redirected to
ECHO -a appends the output of the command to the file,
ECHO rather than overwriting the file
ECHO.
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com
ECHO Modified by Kees Couprie
ECHO http://kees.couprie.org
ECHO and Andrew Cameron
Of course it can be simplified and included in the same "main" batch file....
jaclaz
#19
Posted 10 March 2006 - 09:24 PM
To Gunsmokingman: I was ready to test your solution, but finally I didn't, because I saw a simpler method posted by MHz. I see that you know very well to code in vbs and write more precise scripts (with more checks, better error catching etc), but personally I am in the beginning of the road so I prefer to go step-by-step. I will keep your posts as a reference and maybe I will re-bother you for an explanation.
To MHz: With your help, I finally made possible to have all my programs being executed from the CD. Your code has worked excellent. I understood that the problem was with what the script was considering as the current directory. These 5 lines fixed my .vbs. Thank you.
To Jaclaz: Finally, with this version of tee command, I managed to have it worked. Thanks for the link. I used your syntax and the log file was being created, having inside of it all the screen's output. But another problem came up. The error messages or (more precisely) the stderr stream is not being logged. I see only the standard output. At this moment, I don't remember if the stderr was being showed on the screen, but I think no. Maybe this command filters all the input it takes and gives as the final output (duplicated in the screen and the file) only the stdout stream. But this is not exactly what I need. I want a log file with the full output of my script including any errors. Is it possible to improve the code in the tee.bat so the stderr stream is also being logged?
To Yzowl: I have also tried your solution, but with the same results as above (again, I don't remember if the stderr was being showed on the screen). Any error messages are hidden (the counting of the lines is very cool though). It would be very useful if you added to your .vbs support for the stderr stream (at least in the log file).
#20
Posted 10 March 2006 - 09:34 PM
Here is a link to a place that taught me alot about VBS
scripting. The Hey, Scripting Guy!
Here is a link so you can read more about the send key method.
SendKeys Method



Help

Back to top









