Jeremy S.
Jeremy S.

Reputation: 6643

What does $? mean in Ruby?

I just read the comparison of PHP, Perl, Ruby and Python

http://hyperpolyglot.org/scripting

and saw the following code sample.

files = `ls -l /tmp`
unless $?.success?
  raise "ls failed"
end

files = %x(ls)
unless $?.success?
   raise "ls failed"
end

I was wondering what $? stands for....

Upvotes: 0

Views: 1161

Answers (2)

Softnux
Softnux

Reputation: 2730

$? means exit status of last executed child process

Upvotes: 3

user1061620
user1061620

Reputation:

$? contains the last executed command's exit code. Which can be accessed as $?.exitstatus

Upvotes: 4

Related Questions