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)When it is interpreted by perl:#!/usr/bin/perl -w use strict; print $c;
When it is executed through ssh:$ 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):$ 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
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/5410How 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#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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |