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

Discussion in 'C Programming' started by bgold12, Dec 21, 2008.

  1. bgold12

    bgold12 Guest

    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.
     
    bgold12, Dec 21, 2008
    #1
    1. Advertising

  2. bgold12

    James Kuyper Guest

    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!
     
    James Kuyper, Dec 21, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin
    Replies:
    4
    Views:
    1,080
    David Bolen
    Jul 7, 2003
  2. drs
    Replies:
    0
    Views:
    384
  3. Replies:
    9
    Views:
    739
    Abhijit Soman
    Jan 6, 2005
  4. Vishnu
    Replies:
    0
    Views:
    518
    Vishnu
    Jan 6, 2005
  5. lynology

    Bad File Descriptor Error on strcat/strcpy

    lynology, Aug 18, 2004, in forum: C Programming
    Replies:
    4
    Views:
    527
    Chris Torek
    Aug 18, 2004
Loading...

Share This Page