Batch File Only Echo Errors

March 12, 2010 at 02:29:26
Specs: Windows 7, Quad Core i7, 12gb ram
Hi,

I have a batch file that downloads from an ftp server it downloads from about 5 different sites in one batch file so things fly by fast meaning that I cannot see errors, for example sometimes when it goes to download a file it says file permission denied but it goes to quick for me to ever notice.

Is there a way for me to echo off all the commands that show apart from error messages such as permission denied or file not found.

Simon


See More: Batch File Only Echo Errors

Report •

#1
March 12, 2010 at 02:53:19
I think you're probably stuck with logging the whole thing then looking for errors.

my.bat > log
find "permission" < log

Maybe somebody here has a better plan.


=====================================
Helping others achieve escape felicity

M2


Report •

#2
March 12, 2010 at 03:06:43
Hi M2,

thankyou for the reply, my batch file is very simple is there not a way for the comand prompt to pick up errors when it sees it and write it to a txt document maybe? also is there anyway for me to echo off the uploads so they dont show?

Simon


Report •

#3
March 12, 2010 at 07:31:03
Might learn something myself:

http://www.robvanderwoude.com/redir...


Report •

Related Solutions

#4
March 12, 2010 at 07:47:33
Ok, I read through this however im not good with batch files so that went straight through me and I didnt understand it, how could I use that to only show errors?

Report •

#5
March 16, 2010 at 05:12:41
anyone else?

Report •

#6
March 16, 2010 at 05:29:39
Set your ECHO ON and then run your script:

script >> C:\output.txt 2>&1

Or put some PAUSE commands in there, or put SLEEP.exe (non Windows native)

Don't put PAUSE when redirecting all, cause you cant see when he is pausing (since all output goes to file, not to screen).


Report •

#7
March 16, 2010 at 05:48:42
Ok I am crap at this stuff so here is my batch file, please can you edit it so that it only shows errors

@echo on
COLOR f2
setlocal

::Variables
set f=%temp%\ftpc.txt

::Compose ftp commands file
echo open ftp.************.co.uk>>%f%
echo user *******.co.uk **********>>%f%
echo binary>>%f%
echo cd /htdocs/acatalog>>%f%
echo prompt>>%f%
echo mget *.occ>>%f%
echo mget *.ord>>%f%
echo mdel *.occ>>%f%
echo mdel *.ord>>%f%
echo bye>>%f%

::Execute ftp command
::Use "-d" key for verbose output
ftp -n -d -s:%f%

::Cleanup
del /f /q %f%
endlocal


Report •

#8
March 16, 2010 at 22:55:13
That looks like it will work to get the files.


=====================================
Helping others achieve escape felicity

M2


Report •

#9
March 17, 2010 at 01:46:25
It wasnt getting the files I wanted it to do, it was to list the errors when getting the files

Report •

#10
March 17, 2010 at 02:40:21
That's where we started.


=====================================
Helping others achieve escape felicity

M2


Report •

#11
March 17, 2010 at 02:46:46
I know, but I wasnt sure how to implement it so I gave my code for someone to edit :D

Report •

#12
March 17, 2010 at 03:43:57
re-read #1


=====================================
Helping others achieve escape felicity

M2


Report •

#13
March 17, 2010 at 09:20:17
I think we should explain how to use redirection. I admit, for US it is obvious, but not to everybody. The script is OK by the way.

OK, suppose your script is called script.bat or script.cmd ... navigate to the drive/directory containing that script, then :

C:\> script >> C:\output.txt 2>&1

Then open C:\output.txt

ps inside the FTP, you are in a different command box, so commands like PAUSE would not work (well, I guess) ... but you can remove the BYE command, so that it causes the batch to halt. Or maybe FTP is too smart to for that trick, and ignores this.


Report •

#14
March 18, 2010 at 01:48:33
Thanks TVC, where abouts do I put this:

C:\> script >> C:\output.txt 2>&1

would it go in the batch file?


Report •

#15
March 18, 2010 at 03:58:02
That's the command line ... I've put "C:\>" to indicate that you are entering the script manually from the command line.

Start \ run \ cmd


Report •

#16
March 18, 2010 at 04:46:01
Hi TVC, Ok I am more confused now so when I run that will it automaticly run the batch file for me and show me the errors?

Report •

#17
March 18, 2010 at 15:34:34
Just try it, your computer is not gonna blow up when you type a mistake. Did you ever use the command line before ?

Report •

#18
March 18, 2010 at 17:54:43
this works sort of, but it won't stop/suspend on errors, so they might still scroll off if there's lots of them:
@echo off
ftp -n -s:ftpscript | findstr /b /l "ftp> 5"
::----- end script
i also made assumption all errorcodes start with "5", i might be wrong about that. If there are other error prefixes, someone pls let me know (meantime i will goog around some about ftp).

Report •

#19
March 18, 2010 at 19:14:55
How about redirecting the output to a log file then at the same time run a seperate batch job to scan the log file for your error strings such as permission denied or file not found.

Something like:
C:\> script >> C:\output.txt 2>&1

----Script2.bat
@echo off
:LOOP
echo - FTP Errors at %time% %date% >> ftperrors.txt
find /I "Permission Denied" output.txt >> ftperrors.txt
find /I "File not Found" output.txt >> ftperrors.txt
:SHOW
CLS
type ftperrors.txt
REM Display the file for about 10 seconds...
ping -n 15 127.0.0.1>nul
GOTO LOOP


Report •

#20
March 19, 2010 at 09:26:28
based on stephens excellent suggestion:

@echo off>\uxu & setlocal enabledelayedexpansion
set /a cc=0
start /min \foo.bat
:aa
set /a c=0
for /f "tokens=*" %%a in ('type \uxu') do (
set /a c+=1
set xx=%%a
set test=!xx:~0,1!
if "!test!" gtr "9" (
set cmd=!xx:~5!
if "!cmd!" equ "quit" goto :eof
if "!cmd!" equ "bye" goto :eof
) else (
if !c! gtr !cc! (
if !test! equ 5 (
echo last command: !cmd! +++ result: %%a
)
)
)
)
set /a cc=c
goto :aa
::-------- end batchfile #1
::foo.bat:

ftp -n -s:ff >\uxu
exit
::---- end script
this depends on a ftp giving a digit as 1st char. of all it's output,
to differentiate between the last scripted command. It ignores
all codes except those beginning with 5, assuming those are
the only errorcodes.
i made another version that uses spaces to discriminate the commands,
but that involves altering the ftp script itself (put two spaces in front of each
ftp-command and use those to filter out the commands).
a "ping pause" can be inserted, but that defeats any "real-time" pretense,
(in that case, why not just log it out to file, as M2 suggested way back there.)


Report •

Ask Question