Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Error: sh: cannot duplicate fd 31 to fd 0: Bad file descriptor

Reply
Thread Tools

Error: sh: cannot duplicate fd 31 to fd 0: Bad file descriptor

 
 
bgold12
Guest
Posts: n/a
 
      12-21-2008
I get this error apparently from the following line, where I call ls,
then grep the results, then write the output to a temporarily file all
using the system command:

sprintf(buf, "ls -p \"%s\" |grep \"[^/]$\" >> \"%s\"", dir,
tempfileName ); system(buf);

I have no idea what's causing it, or what the error even means. Can
anyone help?

I'm running Windows XP.
 
Reply With Quote
 
 
 
 
James Kuyper
Guest
Posts: n/a
 
      12-21-2008
bgold12 wrote:
> I get this error apparently from the following line, where I call ls,
> then grep the results, then write the output to a temporarily file all
> using the system command:
>
> sprintf(buf, "ls -p \"%s\" |grep \"[^/]$\" >> \"%s\"", dir,
> tempfileName ); system(buf);
>
> I have no idea what's causing it, or what the error even means. Can
> anyone help?
>
> I'm running Windows XP.


The command string you're passing to system() contains many features
that suggest it's intended for a Unix-like system such as Linux, most
particularly the 'ls' and 'grep' commands. You could have programs named
'ls' and 'grep' installed on your computer, but they are not a built-in
part of Windows. Even if you do have such programs, the way wild cards
are handled by the Windows command interpreter is substantially
different from the way that they are handled by typical Unix shells, so
those functions couldn't be exact substitutes for the unix commands.

If you want to learn what the Windows equivalents of 'ls' and 'grep'
are, the best place to ask would be a Windows-specific newsgroup.

If you're willing to write a Windows-specific program, I believe that
there are functions you can call that will provide you with the
directory list directly, rather than dumping it into a file. Whether
those functions would be useful to you depends upon what your program
does with that file. Again, the best place to ask is a newsgroup
specifically for Windows.

If you want to learn a way of doing that which works equally well on all
C implementations, you're out of luck. Sorry!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why "bad file descriptor"? Geoff Cox Perl 1 12-05-2005 11:29 PM
file.readlines() - gives me error (bad file descriptor) wordsender@gmail.com Python 9 01-06-2005 02:02 PM
RE: file.readlines() - gives me error (bad file descriptor) Vishnu Python 0 01-06-2005 06:33 AM
File::Copy giving "Bad File Descriptor" from sysread Yary H Perl Misc 0 10-03-2004 05:33 PM
Threading issue: [Error 9]: bad file descriptor Kevin Python 4 07-07-2003 10:19 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57