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

B

bgold12

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.
 
J

James Kuyper

bgold12 said:
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!
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top