Hello,

I have just asked at Chatterbox and Corion tell me that it is not possible to change the return code when a perl script fails to compile. He said me about making a wrapper to perl script so it check the return code and return another.

I would like to have the reply and other ideas by written, so I'm posting here the same question.

I have next simple script (test.pl)
#!/usr/bin/perl -w use strict; print $c;
When it is interpreted by perl:
$ perl ~/test.pl Global symbol "$c" requires explicit package name (did you forget to d +eclare "my $c"?) at /home/javi/test.pl line 4. Execution of /home/javi/test.pl aborted due to compilation errors. $ echo $? 255
When it is executed through ssh:
$ ssh localhost perl ~/test.pl Global symbol "$c" requires explicit package name (did you forget to d +eclare "my $c"?) at /home/javi/test.pl line 4. Execution of /home/javi/test.pl aborted due to compilation errors. $ echo $? 255
Like says Corion, I can (on linux):
perl test.pl || if [ \$? -eq 255 ] ; then exit 254; fi

The origin of this question is trying to launch a real script (which I think (but I'm not sure) produces stdout and then it fail with 255 #1 ) with ansible:

https://github.com/ansible/ansible-modules-core/issues/5410

How would you fix this "ansible" issue ?

Any more elegant fix to distinguish between a real 255 ssh returned code and the 255 perl returned code?

ansible only look at ssh return code, and at ssh manpage:

 ssh exits with the exit status of the remote command or with 255 if an error occurred.

Thank you very much (and thank for Corion for the reply at Chatterbox)

Edited 2016/11/02
Created a pull request for ansible which basically add stderr to ansible message when ssh returns 255:
https://github.com/ansible/ansible/pull/18300

#1 updated 2016/11/07

I forgot to use strict on the original script, so it was producing output but returning 255. See:

#!/usr/bin/perl -w print "a\n"; print $c-d; $ perl test.pl Name "main::c" used only once: possible typo at test.pl line 4. a Can't use an undefined value as a symbol reference at test.pl line 4. $ echo $? 255

In reply to 255: perl compilation error code and ssh cannot connect code by i5513

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.