Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Segmentation Fault - Child/Output collision?

by Stormr (Beadle)
on Aug 07, 2001 at 14:45 UTC ( [id://102739]=perlquestion: print w/replies, xml ) Need Help??

Stormr has asked for the wisdom of the Perl Monks concerning the following question:

I am writing a script that is to run a unix make for several different applications, and should parse the result into an easily read report file.
However, when capturing the output I get a 'Segmentation fault' as soon as the make is to save a derived object. The compilations seems to go on fine, but after "Will store derived object xyz.o" I get the fault and the make exits (of course).

I can otherwise (not capturing output) run the make successfully through a script, so the issue is not the ability to save files on the network. Neither is the problem how I retrieve/store the output. In fact, I've tried three different solutions (STDOUT to filehandle via typeglob, fdopen in IO::Handle and (currently, thx grinder) IPC::Open3).

My limited Perl and 'nix experience makes it a bit hard to see the problem. Could it be a buffer problem (need to flush STDOUT before child writes the file?), or anything else??

Appreciate any help!

/ Stormr
  • Comment on Segmentation Fault - Child/Output collision?

Replies are listed 'Best First'.
Re: Segmentation Fault - Child/Output collision?
by clemburg (Curate) on Aug 07, 2001 at 17:26 UTC

    After some CB chatter, Stormr said the problem even shows up when he is calling the make command directly from the shell. So the problem does not appear to be related to his Perl code.

    Christian Lemburg
    Brainbench MVP for Perl
    http://www.brainbench.com

Re: Segmentation Fault - Child/Output collision?
by Stormr (Beadle) on Aug 07, 2001 at 15:09 UTC

    Here's the important parts of the code...

    open OUTLOG, ">$outlog_filename" or die "$!"; open ERRLOG, ">$errlog_filename" or die "$!"; chdir "$src_dir/src"; #Runs the make, sending output to logs. FAKEHANDLE is a closed filehan +dle. open3( \*FAKEHANDLE, ">&OUTLOG", ">&ERRLOG", "$make_cmd -v -f $makefil +e" ); close OUTLOG; close ERRLOG;
    / Stormr
      From perldoc IPC::Open3:
      It will not create these file handles for you. You have to do this yourself. So don't pass it empty variables expecting them to get filled in for you.
      So you can't pass FAKEHANDLE like you do; instead, you'd need to open /dev/null for reading and pass that.

      However, if as in your example you're not interested in communicating with your process as it runs, why not just say

      system("$make_cmd -v -f $makefile > $outlog_filename 2> $errlog_filena +me")
      instead?

        Clarifying: FAKEHANDLE *is* a real filehandle, as said in the comment ("FAKEHANDLE is a closed filehandle"), so it runs just fine. I didn't include the code lines treating it though, as I found them rather redundant.

        Unfortunately system() does just the same thing here as my IPC::Open3 call, and as well as being an equally nice bit of code (nicer?), it doesn't prevent the segmentation fault.

        / Stormr

      If all you want to do is captrue the output of the $make_cmd and send it to your log files why not just use backtics and do this:

      my $output = `$make_cmd -v -f $makefile`; print OUTLOG $output;

      cheers

      tachyon

      s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://102739]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-23 13:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found