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

[PATCH] Add mention of $? in backticks documentation #15073

Closed
p5pRT opened this issue Dec 5, 2015 · 5 comments
Closed

[PATCH] Add mention of $? in backticks documentation #15073

p5pRT opened this issue Dec 5, 2015 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented Dec 5, 2015

Migrated from rt.perl.org#126821 (status was 'resolved')

Searchable as RT126821$

@p5pRT
Copy link
Author

p5pRT commented Dec 5, 2015

From madcityzen@gmail.com

A while back, a few people in freenode #perl were asking about how to get the exit status of a program executed with qx(). The documentation for qx() does not mention anything about $?, while the docs for system() do.

Here's a proposed doc patch. I explicitly copy/pasted the system() error handling code rather than just referred the reader to `perldoc -f system` for more information because it seemed friendlier, and the idiom is pretty much set in stone.

Doug Bell
madcityzen@​gmail.com

@p5pRT
Copy link
Author

p5pRT commented Dec 5, 2015

From madcityzen@gmail.com

0001-mention-in-backticks-documentation.patch
From 306a1c934975338b3cfaad8b947b582c35f0eb18 Mon Sep 17 00:00:00 2001
From: Doug Bell <madcityzen@gmail.com>
Date: Tue, 24 Nov 2015 02:31:38 -0600
Subject: [PATCH] mention $? in backticks documentation

Backticks work like system(), in that they use $? for the child exit
code. Mention that so people know to look in $? when their program
fails.
---
 pod/perlop.pod | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/pod/perlop.pod b/pod/perlop.pod
index 1691614..50ee6e0 100644
--- a/pod/perlop.pod
+++ b/pod/perlop.pod
@@ -2309,6 +2309,21 @@ when they're the right way to get something done.  Perl was made to be
 a glue language, and one of the things it glues together is commands.
 Just understand what you're getting yourself into.
 
+Like C<system>, backticks put the child process exit code in C<$?>.
+If you'd like to manually inspect failure, you can check all possible
+failure modes by inspecting C<$?> like this:
+
+    if ($? == -1) {
+        print "failed to execute: $!\n";
+    }
+    elsif ($? & 127) {
+        printf "child died with signal %d, %s coredump\n",
+            ($? & 127),  ($? & 128) ? 'with' : 'without';
+    }
+    else {
+        printf "child exited with value %d\n", $? >> 8;
+    }
+
 See L</"I/O Operators"> for more discussion.
 
 =item C<qw/I<STRING>/>
-- 
2.4.9 (Apple Git-60)

@p5pRT
Copy link
Author

p5pRT commented Dec 7, 2015

From @rjbs

Thanks, applied as 7cf4dd3.

--
rjbs

@p5pRT
Copy link
Author

p5pRT commented Dec 7, 2015

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Dec 7, 2015

@rjbs - Status changed from 'open' to 'resolved'

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

No branches or pull requests

1 participant