nested popen()'s lead to fgets() failure on 64-bit only
Corinna Vinschen
corinna-cygwin@cygwin.com
Mon Jan 13 12:09:00 GMT 2014
On Jan 12 21:15, David Levine wrote:
> Hi,
>
> The program below works just fine on 32-bit Cygwin:
> buf1 = /usr/bin/file.exe
> buf2 = /usr/bin/file.exe: application/x-dosexec
>
> But on 64-bit Cygwin (2.831), the second fgets() fails:
That's the version number of the setup-x86_64.exe tool, not the version
number of Cygwin. Try `uname -r'.
> buf1 = /usr/bin/file.exe
> fgets2: No error
>
> It only seems to happen with nested popen()'s. Is it due to a
> problem in the Cygwin lib?
Works fine for me on Cygwin 1.7.27:
$ uname -rm
1.7.27(0.271/5/3) x86_64
$ file --version
file-5.13
magic file from /usr/share/misc/magic
$ ./popen-test
buf1 = /usr/bin/file.exe
buf2 = /usr/bin/file.exe: application/x-dosexec
$
The fact that fgets returns NULL doesn't mean an error occured. fgets
also returns NULL at EOF, meaning no output in this case, which you
should test, too:
if (fgets(buf2, sizeof buf2, f2))
printf(" buf2 = %s", buf2);
else if (feof (f2))
fputs ("fgets2 EOF\n", stderr);
else
perror("fgets2");
Maybe you're calling the wrong file command? What's your $PATH set to?
What if you change your popen call to run /usr/bin/file.exe with full
path?
if ((f2 = popen("/usr/bin/file --mime-type /usr/bin/file.exe", "r")))
Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Maintainer cygwin AT cygwin DOT com
Red Hat
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20140113/11a9b498/attachment.sig>
More information about the Cygwin
mailing list