Print: producing no output

11,917

Solution 1

The problem was not STDOUT missing or redirected from the shell, but rather that the shell was set to send a carriage return without a newline when writing a prompt, thus overwriting all output sent to the same line.

Specifically, my old version of zsh had promptcr set. See question 3.23 here for more information.

Solution 2

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
Share:
11,917
JoshJordan
Author by

JoshJordan

a

Updated on July 19, 2022

Comments

  • JoshJordan
    JoshJordan almost 2 years

    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
    
  • ikegami
    ikegami over 12 years
    @JoshJordan, Also, try \perl instead of perl. Maybe you have an alias?
  • ikegami
    ikegami over 12 years
    @JoshJordan, Also, try "a\n" instead of "a". You are perhaps overwriting your output with later output (e.g. your prompt)
  • ikegami
    ikegami over 12 years
    (I had actually mentioned that.)