Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print: producing no output

Tags:

printing

perl

I'm fairly confused. I just got a new development machine, and perl appears to be outputting nothing for print commands.

#!/usr/bin/perl
use warnings;
use strict;
print "A";
print STDOUT "B";
print STDERR "C";
open FH, ">", "testprint';
print FH "D";
close FH;

Produces nothing in the console, and testprint becomes a 1-bye (empty) file.

Even this produces nothing:

perl -e "print 'a';"

This occurs for both perl binaries that happen to be on my machine. I'm stumped about where to start debugging this problem. Any ideas?

EDIT:

perl -v

This is perl, v5.8.8 built for x86_64-linx-thread-multi

and

which perl

/usr/bin/perl
like image 565
JoshJordan Avatar asked Mar 22 '12 21:03

JoshJordan


1 Answers

I believe the problem exists outside of Perl. Either

  • the terminal in some unusual state when you ran the script,
  • perl's parent process redirected perl's output away from the terminal, or
  • perl's parent process did not provide a STDOUT and STDERR for perl.

You might be able to gather more information by actually checking if print returned an error. (It always baffles me why people don't check for errors when something doesn't work they way they expect it to work.)

perl -we'print("a") or die("Can'\''t print: $!\n");'

You might be able to gather more information by using strace or whatever it's called on your system. (Look for write(1 and write(2.)

strace perl -we'print("a") or die("Can'\''t print: $!\n");'

But those should print nothing at all if the problem is outside of Perl, which is why it might be wise to try redirecting the output to a file and then examining the file and its size.

perl -we'print("a") or die("Can'\''t print: $!\n");' 1>out 2>err
like image 181
ikegami Avatar answered Oct 24 '22 07:10

ikegami