开发者

Exit status of process started with open()

开发者 https://www.devze.com 2023-01-06 21:23 出处:网络
What is the exist sta开发者_如何学Pythontus of a process opened with open() e.g.: f = open(\"|#{cmd}\", \'r\')

What is the exist sta开发者_如何学Pythontus of a process opened with open() e.g.:

f = open("|#{cmd}", 'r')
while char = f.getc
  do something ...
end
f.????


$? will contain the exit status after you have closed f. e.g.

irb(main):024:0> f = open("|#{cmd}", "r")
=> #<IO:0x2d7e9dc>
# read from f here
irb(main):025:0> f.close
=> nil
irb(main):026:0> $?
=> #<Process::Status: pid=3576,exited(0)>
irb(main):027:0> $?.exitstatus
=> 0
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号