File: block.rb

package info (click to toggle)
ruby-open4 1.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 184 kB
  • sloc: ruby: 806; makefile: 2
file content (19 lines) | stat: -rw-r--r-- 472 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
require 'open4'
#
# when using block form the child process is automatically waited using
# waitpid2
#

status =
  Open4::popen4("sh") do |pid, stdin, stdout, stderr|
    stdin.puts "echo 42.out"
    stdin.puts "echo 42.err 1>&2"
    stdin.close

    puts "pid        : #{ pid }"
    puts "stdout     : #{ stdout.read.strip }"
    puts "stderr     : #{ stderr.read.strip }"
  end

    puts "status     : #{ status.inspect }"
    puts "exitstatus : #{ status.exitstatus }"