U
usenet
hello, world\n
I've read the perlfaq#8 up and down, can spell File::Temp backwards,
but still, I'm puzzled because no matter what I do, I get an empty
tempfile when it clearly should not be empty. Here's what I want:
Run "gcc -E -v -dM -x -c /dev/null" and write stderr to a temp file
while reading stderr from some handle (exactly so. Suggestions like
"write two temp files; see perlfaq8" are inelegant). The way I try to
combine tempfile and open3 is not correct and I want to know my
mistake. Here's a complete program to illustrate the issue:
#!/usr/local/bin/perl -w
use strict;
use File::Temp qw(tempfile);
use IPC::Open3;
use Symbol qw(gensym);
# A command producing output on both stdout and stderr.
my @cmd = ('gcc', '-E', '-v', '-dM', '-x', 'c', '/dev/null');
# Temp file where @cmd's stdout should go.
my ($filehandle, $filename) = tempfile ('predef-XXXXXX', DIR => ".",
SUFFIX => '.h', UNLINK => 0);
# What I want: write stdout to $filehandle and end up in $filename;
# read stderr from <ERR>.
my $pid = open3 (gensym, $filehandle, \*ERR, @cmd);
while (<ERR>) {
print $_; # This works fine.
}
waitpid ($pid, 0) or die "$!";
close $filehandle or die "$!";
# What I get: 0 bytes even though it should be many lines.
# I would have expected $filename to be more than a zero-length
file...
# What exactly is the relation between $filehandle and $filename?
system ('wc', $filename);
The output is:
Using built-in specs.
Target: i386-undermydesk-freebsd
Configured with: FreeBSD/i386 system compiler
Thread model: posix
gcc version 4.2.1 20070719 [FreeBSD]
/usr/libexec/cc1 -E -quiet -v -D_LONGLONG /dev/null -dM
ignoring duplicate directory "/usr/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/include
End of search list.
0 0 0 ./predef-Om1rvd.h
The part form "Using built-in specs." to "End of search list." is
gcc's stderr.
Stdout has about 50 "#define" directives that you can see when running
the gcc command from the shell command line.
Thanks for any clue. Merry Christmas!
Regards,
Jens
I've read the perlfaq#8 up and down, can spell File::Temp backwards,
but still, I'm puzzled because no matter what I do, I get an empty
tempfile when it clearly should not be empty. Here's what I want:
Run "gcc -E -v -dM -x -c /dev/null" and write stderr to a temp file
while reading stderr from some handle (exactly so. Suggestions like
"write two temp files; see perlfaq8" are inelegant). The way I try to
combine tempfile and open3 is not correct and I want to know my
mistake. Here's a complete program to illustrate the issue:
#!/usr/local/bin/perl -w
use strict;
use File::Temp qw(tempfile);
use IPC::Open3;
use Symbol qw(gensym);
# A command producing output on both stdout and stderr.
my @cmd = ('gcc', '-E', '-v', '-dM', '-x', 'c', '/dev/null');
# Temp file where @cmd's stdout should go.
my ($filehandle, $filename) = tempfile ('predef-XXXXXX', DIR => ".",
SUFFIX => '.h', UNLINK => 0);
# What I want: write stdout to $filehandle and end up in $filename;
# read stderr from <ERR>.
my $pid = open3 (gensym, $filehandle, \*ERR, @cmd);
while (<ERR>) {
print $_; # This works fine.
}
waitpid ($pid, 0) or die "$!";
close $filehandle or die "$!";
# What I get: 0 bytes even though it should be many lines.
# I would have expected $filename to be more than a zero-length
file...
# What exactly is the relation between $filehandle and $filename?
system ('wc', $filename);
The output is:
Using built-in specs.
Target: i386-undermydesk-freebsd
Configured with: FreeBSD/i386 system compiler
Thread model: posix
gcc version 4.2.1 20070719 [FreeBSD]
/usr/libexec/cc1 -E -quiet -v -D_LONGLONG /dev/null -dM
ignoring duplicate directory "/usr/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/include
End of search list.
0 0 0 ./predef-Om1rvd.h
The part form "Using built-in specs." to "End of search list." is
gcc's stderr.
Stdout has about 50 "#define" directives that you can see when running
the gcc command from the shell command line.
Thanks for any clue. Merry Christmas!
Regards,
Jens