Batch file help

M

MSBhhNish

I have a batch file that I wrote on a Win2K system where
I have something like:
copy file1.txt f:\file2.txt > NUL:
On win2K if I have an error, such as not enough room on f:,
the error message is displayed on the Console window. If
no error, the "1 file(s) copied" message goes out to null.

However on WinXP, both the stdout and stderr message goes
to NUL:. Is there a way to write the copy command so
that it emulates Win2K?

TIA
 
P

Pegasus \(MVP\)

MSBhhNish said:
I have a batch file that I wrote on a Win2K system where
I have something like:
copy file1.txt f:\file2.txt > NUL:
On win2K if I have an error, such as not enough room on f:,
the error message is displayed on the Console window. If
no error, the "1 file(s) copied" message goes out to null.

However on WinXP, both the stdout and stderr message goes
to NUL:. Is there a way to write the copy command so
that it emulates Win2K?

TIA

Try this:
copy file1.txt f:\file2.txt 1> NUL

A far better way would go like so:

@echo off
copy /y file1.txt f:\file2.txt 1>nul 2>nul
if %ErrorLevel% GTR 0 (
echo.
echo Insufficient space on drive F:.
echo Do something about it!
echo.
echo Press the space bar to close this window.
pause > nul
)
 
M

MSBhhNish

Pegasus said:
Try this:
copy file1.txt f:\file2.txt 1> NUL

A far better way would go like so:

@echo off
copy /y file1.txt f:\file2.txt 1>nul 2>nul
if %ErrorLevel% GTR 0 (
echo.
echo Insufficient space on drive F:.
echo Do something about it!
echo.
echo Press the space bar to close this window.
pause > nul
)

The thing is, I don't want to assume that the error will
be "Insufficient space". I want to display whatever is
returned by the copy...
 
P

Pegasus \(MVP\)

MSBhhNish said:
The thing is, I don't want to assume that the error will
be "Insufficient space". I want to display whatever is
returned by the copy...

Same idea!

@echo off
copy /y file1.txt f:\file2.txt 1>nul 2>nul
if %ErrorLevel% GTR 0 (
echo.
echo Problem copying the file. Do something about it!
echo.
echo Press the space bar to close this window.
pause > nul
)
 
M

MSBhhNish

Pegasus said:
Same idea!

@echo off
copy /y file1.txt f:\file2.txt 1>nul 2>nul
if %ErrorLevel% GTR 0 (
echo.
echo Problem copying the file. Do something about it!
echo.
echo Press the space bar to close this window.
pause > nul
)

Your solution is too generic. I hate to give generic
answers to my users. They won't have any idea what the
problem is and they'll just call me.

Does anyone else have a solution to my problem?
 
3

3c273

Pegasus gave you the answer in the first reply.
copy file1.txt f:\file2.txt 1> NUL
Louis
 
J

Jon

There is plenty of evidence to suggest that "MSBhhNish"

I don't get that behaviour with WinXP - error output goes to the console
window. So I would reexamine the exact command you are using - it may be
executing without any error messages (but not necessarily what you thought
you were executing), or there may some other error at another position in
your batch file, such that the command never executes at all. Turning echo
on or putting a few 'pause' statements in the batch file might help in
troubleshooting.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top