Skip to content

Commit

Permalink
EM.system can take multiple arguments for the command
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm1 committed Apr 15, 2009
1 parent 9b7a76d commit e3c02c9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/em/processes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ def EventMachine::system cmd, *args, &cb
cb ||= args.pop if args.last.is_a? Proc
init = args.pop if args.last.is_a? Proc

# merge remaining arguments into the command
cmd = ([cmd] + args.map{|a|a.to_s.dump}).join(' ')

EM.get_subprocess_pid(EM.popen(cmd, SystemCmd, cb) do |c|
init[c] if init
end.signature)
Expand Down
26 changes: 25 additions & 1 deletion tests/test_processes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,30 @@ def test_em_system_with_two_procs
})
}

assert_equal($out, "hello\n")
assert_equal("hello\n", $out)
end

def test_em_system_cmd_arguments
EM.run{
EM.system('sh', '--version', proc{ |process|
}, proc{ |out,status|
$out = out
$status = status
EM.stop
})
}

assert_match(/version/i, $out)
end

def test_em_system_spaced_arguments
EM.run{
EM.system('ruby', '-e', 'puts "hello"', proc{ |out,status|
$out = out
EM.stop
})
}

assert_equal("hello\n", $out)
end
end

0 comments on commit e3c02c9

Please sign in to comment.