1.3.10-1: bash-2.05a-3: "Bad file number" using redirector >

Mark Edgar medgar@student.gc.maricopa.edu
Mon Apr 15 11:20:00 GMT 2002


When using the standard '>' or '>>' redirector to redirect output to a
file on a NetWare directory, I get a "Bad file number" error.  I also
have ash-20020131-1 installed, and it does not have this problem.


# Here is the problem:
bash$ cat >/cygdrive/h/foofile
foo
cat: write error: Bad file number

# But it works fine in ash:
ash$ cat >/cygdrive/h/foofile
foo
^D

# bash builtins also work ok
bash$ echo foo >/cygdrive/h/foofile

# /bin/echo doesn't give an error, but the file remains empty,
# unlike the builtin echo
bash$ /bin/echo foo >/cygdrive/h/foofile
bash$ /bin/ls -l /cygdrive/h/foofile
-rw-r--r--    0 medgar   users           0 Apr 11 15:19
/cygdrive/h/foofile


Keep in mind, this happens not just with cat, but with any program whose
stdout I wish to redirect to a network file.

Some more information:

Under Windows, drive H is mapped to my home directory on the NetWare
server.
Also, my Cygwin home directory is a symlink to this drive:


$ /bin/ls -l /home/medgar
total 0
lrwxrwxrwx    1 medgar   users          94 Apr 11 14:53 medgar ->
/cygdrive/h


I have been running Cygwin with this setup for 6 months now and I have
not noticed this problem before.  This problem exists on other mounted
NetWare drives which are also writable.  I'm not sure about files on
Microsoft network drives.

I have also found a (possibly) related problem with rcs-5.7-2.  It is a
similar problem in that the program works fine when working with files
on a local drive, but fails when working with files on a network drive.


# create new file 'blah'
$ vi blah
# checkin the new file
$ ci -t-blah -l blah
blah,v  <--  blah
initial revision: 1.1
ci: blah,v: Permission denied
ci: saved in ,blah,


Again, this is not a problem when working with files on a local drive.

I found a couple of other messages in the cygwin list that reference
"Bad file number", but neither stated that the problem relates to
working
with files on network drives.

					-Mark

You can stop reading here unless you've really nothing better to do.


I wrote a simple test suite, and ran 12 different commands in 20 trials.
The results are in the table below.

bash commands:

A $ cat >/cygdrive/h/foo
B $ cat >>/cygdrive/h/foo
C $ cat >//server/volume/users/medgar/foo
D $ cat >>//server/volume/users/medgar/foo

E $ echo >/cygdrive/h/foo
F $ echo >>/cygdrive/h/foo
G $ echo >//server/volume/users/medgar/foo
H $ echo >>//server/volume/users/medgar/foo

I $ /bin/echo >/cygdrive/h/foo
J $ /bin/echo >>/cygdrive/h/foo
K $ /bin/echo >//server/volume/users/medgar/foo
L $ /bin/echo >>//server/volume/users/medgar/foo

S=Success
F=Failure


Test suite results:

          cat     echo    /bin/echo
        -------  -------  -------
trial	A B C D  E F G H  I J K L
=================================
1       S F S S  S S F F  S F S S
2       S S S S  S S F F  S F S S
3       S F S F  S S F F  S S S F
4       S F S S  S S F F  S S S S
5       S F S S  S S F F  S S S S
6       S F F F  S S F F  F F F F
7       S F F F  S S F F  F F F F
8       F F F F  S S F F  F F F F
9       S F F F  S S F F  S F F F
10      S F F F  S S F F  F F S F
11      F F F F  S S F F  F F F F
12      F F F F  S S F F  F F F F
13      F F F S  S S F F  F F F F
14      F F S F  S S F F  F F F F
15      F F F F  S S F F  S F F F
16      F F F F  S S F F  F S F F
17      F F F F  S S F F  S F F F
18      S F S F  S S F F  F F F F
19      F F S F  S S F F  S F F F
20      F F F S  S S F F  F F F F


Contrary to what I stated above, the offending command lines actually
succeed sometimes.  Interestingly however, from an interactive session,
I cannot get a single one of these offending command lines to work
just once.  At any rate, they all intermittently fail, which should
never happen.

Other results from the test suite are that the builtin echo to the
/cygdrive/... path always success, and the builtin echo to the UNC name
//server/... always fails.  This is an interesting result, but I don't
really care about it as I don't use UNC file paths.  However, it may be
a clue as to why the other commands fail intermittently.

To be thorough in my testing, I should have included commands other than
'cat' and 'echo'.  I should have had cases where the output is
redirected
to a file on a local drive.  I should also have attempted to install
Cygwin on another machine and maybe get someone else to log in and try
to write to their NetWare space.  Sadly, time does not grow on trees.

The actually test suite shell script follows.  Before running it, you
will need to modify the file paths. You will also need to create a file
called 'foostd' that contains one (1) line with only the word 'foo' on
it.
This file should be four (4) bytes.  I would have had the script create
it automatically, but I can't guarantee that it would succeed in doing
so!

					-Mark
=== begin included script ===
#!/bin/bash

F1=/cygdrive/h/foofile
F2=//server/volume/directory/foofile

works() {
  cmp -s foostd "$1"
}

file=$F1.cat1
rm -f $file
cat >$file <<EOM
foo
EOM
works $file && echo 'SUCCESS: cat >'$file || echo 'FAILED: cat >'$file

file=$F1.catA1
rm -f $file
cat >>$file <<EOM
foo
EOM
works $file && echo 'SUCCESS: cat >>'$file || echo 'FAILED: cat >>'$file

file=$F2.cat2
rm -f $file
cat >$file <<EOM
foo
EOM
works $file && echo 'SUCCESS: cat >>'$file || echo 'FAILED: cat >'$file

file=$F2.catA2
rm -f $file
cat >>$file <<EOM
foo
EOM
works $file && echo 'SUCCESS: cat >>'$file || echo 'FAILED: cat >>'$file


file=$F1.echo1
rm -f $file
echo foo >$file
works $file && echo 'SUCCESS: echo >>'$file || echo 'FAILED: echo
>'$file

file=$F1.echoA1
rm -f $file
echo foo >>$file
works $file && echo 'SUCCESS: echo >>'$file || echo 'FAILED: echo
>>'$file

file=$F2.echo2
rm -f $file
echo foo >$file
works $file && echo 'SUCCESS: echo >>'$file || echo 'FAILED: echo
>'$file

file=$F2.echoA2
rm -f $file
echo foo >>$file
works $file && echo 'SUCCESS: echo >>'$file || echo 'FAILED: echo
>>'$file


file=$F1.binecho1
rm -f $file
/bin/echo foo >$file
works $file && echo 'SUCCESS: /bin/echo >>'$file || echo 'FAILED:
/bin/echo >'$file

file=$F1.binechoA1
rm -f $file
/bin/echo foo >>$file
works $file && echo 'SUCCESS: /bin/echo >>'$file || echo 'FAILED:
/bin/echo >>'$file

file=$F1.binecho2
rm -f $file
/bin/echo foo >$file
works $file && echo 'SUCCESS: /bin/echo >>'$file || echo 'FAILED:
/bin/echo >'$file

file=$F1.binechoA2
rm -f $file
/bin/echo foo >>$file
works $file && echo 'SUCCESS: /bin/echo >>'$file || echo 'FAILED:
/bin/echo >>'$file

=== end script ===

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list