Perl5-IDEA icon indicating copy to clipboard operation
Perl5-IDEA copied to clipboard

Can't execute a script with --version argument

Open juanrad opened this issue 3 years ago • 6 comments

System Information:

  • IDE name and version:
    • Pycharm 2021.3.2 (Community Edition)
    • Build #PC-213.6777.50, built on January 27, 2022
    • Runtime version: 11.0.13+7-b1751.25 amd64
    • VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
  • Perl5 plugin version: 2021.3.1
  • JRE version
openjdk 11.0.11 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2.20.04)
OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2.20.04, mixed mode, sharing
  • OS name and version: Ubuntu 20.04.3 LTS

Steps to reproduce

Create this script example.pl :

use 5.24.4;
use strict;
use warnings FATAL => 'all';
use English qw(-no_match_vars);

say "Somebody call me with following arguments: " . join(' ', @ARGV);

and run with arguments: --version 2 --other_arg value --boolean_arg

This outputs the following

/opt/perlbrew/bin/perlbrew exec -q --with perl-5.24.4 /opt/perlbrew/perls/perl-5.24.4/bin/perl /home/juan.diego/workspace/debug_with_version_argument/example.pl --version 2 --other_arg value --boolean_arg
/opt/perlbrew/bin/perlbrew  - App::perlbrew/0.92

Process finished with exit code 0

and do nothing more, without actually executed the script.

Possible solution

It seems to me that the --version argument is passed to the App::perlbrew module (which processes here.)

I can avoid this problem with the following workarround: specify the parameters with -- at the begining`:

/opt/perlbrew/bin/perlbrew exec -q --with perl-5.24.4 /opt/perlbrew/perls/perl-5.24.4/bin/perl /home/juan.diego/workspace/debug_with_version_argument/example.pl -- --version 2 --other_arg value --boolean_arg
Somebody call me with following arguments: -- --version 2 --other_arg value --boolean_arg

Process finished with exit code 0

I'm wondering if it's possible to preceed all arguments with -- to avoid this problem in all executions.

Hope this is the right place to post this issue.

Many thanks for developing this plugin!

juanrad avatar Feb 02 '22 14:02 juanrad

This is quite interesting case. Actually it looks to me more like problem of the perlbrew. From user perspective this is unexpected behavior and I would expect that arguments after the script name belongs to the script, not to the perlbrew. I'm not sure if generic approach with -- will work for everyone well.

hurricup avatar Apr 28 '22 18:04 hurricup

There is also an issue of passing arguments to the perl. I mean that we can have 3 groups of arguments here:

  1. For perbrew
  2. For perl
  3. For the script.

And i'm not sure how properly pass them besides just ordering them like perlbrew [perlbrewargs] perl [perlargs] script.pl [scriptargs] There should be some proper unix approach for this.

hurricup avatar Apr 28 '22 18:04 hurricup

Could you please try to run command with POSIXLY_CORRECT=true? See: https://metacpan.org/pod/Getopt::Long#require_order

hurricup avatar Apr 29 '22 08:04 hurricup

Despite what documentation says, setting POSIXLY_CORRECT doesn't change the output.

$ POSIXLY_CORRECT=true /opt/perlbrew/bin/perlbrew exec -q --with perl-5.24.4 /opt/perlbrew/perls/perl-5.24.4/bin/perl /home/juan.diego/workspace/debug_with_version_argument/example.pl --version 2 --other_arg value --boolean_arg
/opt/perlbrew/bin/perlbrew  - App::perlbrew/0.92

My version of Getopt::Long is

$ perl -MGetopt::Long -E 'say "$Getopt::Long::VERSION"'
2.52

I think the approach you suggest seems fair, but maybe the Getopt module fails to identify when a certain string it is not an option, although it should.

It seems more likely to me that perlbrew it's doing something funny in it use of the Getopt module.

edit: spelling

juanrad avatar Apr 29 '22 09:04 juanrad

Feels like it worth asking in Perlbrew repo about this problem. Because technically it's unrelated to the plugin or IDE. You still may want to run perlbrew ... perl ... script --version in some generic way and it should work.

hurricup avatar Apr 29 '22 11:04 hurricup

Related https://github.com/gugod/App-perlbrew/blob/af2ff9ffea3763efb236c9be13952bf67527b755/lib/App/perlbrew.pm#L125

hurricup avatar Apr 29 '22 13:04 hurricup