Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using both :out and :err in run() reports the wrong exit code #6072

Open
p6rt opened this issue Feb 14, 2017 · 2 comments
Open

Using both :out and :err in run() reports the wrong exit code #6072

p6rt opened this issue Feb 14, 2017 · 2 comments
Labels

Comments

@p6rt
Copy link

@p6rt p6rt commented Feb 14, 2017

Migrated from rt.perl.org#130781 (status was 'new')

Searchable as RT130781$

@p6rt
Copy link
Author

@p6rt p6rt commented Feb 14, 2017

From @briandfoy

Here's a program that starts another program with run() with
various combinations of :out and :err. When :out and :err are both
specified, the exit code is incorrect. This is 2017.01​:

  #!/Applications/Rakudo/bin/perl6

  use v6;

  my $filename = 'null-program.p6';
  my $fh = open $filename, :w;
  END { unlink $filename }

  $fh.put( q​:to/HERE/ );
  #!{ $*EXECUTABLE }
  $*ERR.say( Q/This goes to standard error/ );
  $*OUT.say( Q/This goes to standard output/ );

  exit 137;
  HERE

  {
  my $proc = run $*EXECUTABLE, $filename;
  say "1. Exit is { $proc.exitcode }";
  }

  {
  my $proc = run $*EXECUTABLE, $filename, :out;
  $proc.out.slurp-rest( :close );
  say "2. Exit is { $proc.exitcode }";
  }

  {
  my $proc = run $*EXECUTABLE, $filename, :err;
  $proc.err.slurp-rest( :close );
  say "3. EHere's a program that starts another program with run() with
various combinations of :out and :err. When :out and :err are both
specified, the exit code is incorrect​:

  #!/Applications/Rakudo/bin/perl6

  use v6;

  my $filename = 'null-program.p6';
  my $fh = open $filename, :w;
  END { unlink $filename }

  $fh.put( q​:to/HERE/ );
  #!{ $*EXECUTABLE }
  $*ERR.say( Q/This goes to standard error/ );
  $*OUT.say( Q/This goes to standard output/ );

  exit 137;
  HERE

  {
  my $proc = run $*EXECUTABLE, $filename;
  say "1. Exit is { $proc.exitcode }";
  }

  {
  my $proc = run $*EXECUTABLE, $filename, :out;
  $proc.out.slurp-rest( :close );
  say "2. Exit is { $proc.exitcode }";
  }

  {
  my $proc = run $*EXECUTABLE, $filename, :err;
  $proc.err.slurp-rest( :close );
  say "3. Exit is { $proc.exitcode }";
  }

  {
  my $proc = run $*EXECUTABLE, $filename, :out, :err;
  $proc.out.slurp-rest( :close );
  $proc.err.slurp-rest( :close );
  say "4. Exit is { $proc.exitcode }";
  }

The fourth situation reports a different exit code​:

  This goes to standard error
  This goes to standard output
  1. Exit is 137
  This goes to standard error
  2. Exit is 137
  This goes to standard output
  3. Exit is 137
  4. Exit is 0xit is { $proc.exitcode }";
  }

  {
  my $proc = run $*EXECUTABLE, $filename, :out, :err;
  $proc.out.slurp-rest( :close );
  $proc.err.slurp-rest( :close );
  say "4. Exit is { $proc.exitcode }";
  }

The fourth situation reports a different exit code​:

  This goes to standard error
  This goes to standard output
  1. Exit is 137
  This goes to standard error
  2. Exit is 137
  This goes to standard output
  3. Exit is 137
  4. Exit is 0

@AlexDaniel
Copy link
Member

@AlexDaniel AlexDaniel commented Feb 8, 2020

Code snippet that is not mangled:

use v6;

my $filename = 'sandbox/null-program.p6';
my $fh = open $filename, :w;
END { unlink $filename }

$fh.put: 
$*ERR.say( Q/This goes to standard error/ );
$*OUT.say( Q/This goes to standard output/ );

exit 137;
;

{
my $proc = run $*EXECUTABLE, $filename;
say "1. Exit is { $proc.exitcode }";
}

{
my $proc = run $*EXECUTABLE, $filename, :out;
$proc.out.slurp-rest( :close );
say "2. Exit is { $proc.exitcode }";
}

{
my $proc = run $*EXECUTABLE, $filename, :err;
$proc.err.slurp-rest( :close );
say "3. Exit is { $proc.exitcode }";
}

{
my $proc = run $*EXECUTABLE, $filename, :out, :err;
$proc.out.slurp-rest( :close );
$proc.err.slurp-rest( :close );
say "4. Exit is { $proc.exitcode }";
}

Output on all releases: https://gist.github.com/AlexDaniel/fca7b261d6a4e46290d2fdb7645e5e2a

Seems to be fixed after (2017-06-12) rakudo/rakudo@92bd7e4 just like #4456

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.