1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* process.c (check_exec_redirect): Open the file in write mode for

redirect from [:out, :err].
  Proposed and implemented by Yusuke Endoh.
  [ruby-dev:41430] [Feature #3348]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45828 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2014-05-05 13:37:09 +00:00
parent edacb3a94a
commit 7a69a3583c
4 changed files with 41 additions and 1 deletions

View file

@ -1,3 +1,10 @@
Mon May 5 22:29:47 2014 Tanaka Akira <akr@fsij.org>
* process.c (check_exec_redirect): Open the file in write mode for
redirect from [:out, :err].
Proposed and implemented by Yusuke Endoh.
[ruby-dev:41430] [Feature #3348]
Mon May 5 21:52:35 2014 Tanaka Akira <akr@fsij.org> Mon May 5 21:52:35 2014 Tanaka Akira <akr@fsij.org>
* ext/pathname/lib/pathname.rb (cleanpath_aggressive): make all * ext/pathname/lib/pathname.rb (cleanpath_aggressive): make all

10
NEWS
View file

@ -27,6 +27,11 @@ with all sufficient information, see the ChangeLog file.
* New methods * New methods
* IO#statfs returns filesystem information as File::Statfs. (experimental) * IO#statfs returns filesystem information as File::Statfs. (experimental)
* Process
* Extended method:
* Process execution methods such as Process.spawn opens the file in write
mode for redirect from [:out, :err].
* Symbol * Symbol
* New methods * New methods
* Symbol.find(str) returns whether given string is defined as symbol or not. * Symbol.find(str) returns whether given string is defined as symbol or not.
@ -64,6 +69,11 @@ with all sufficient information, see the ChangeLog file.
arguments of the lambda, if just an array is yielded and its length arguments of the lambda, if just an array is yielded and its length
matches. matches.
* Process
* Process execution methods such as Process.spawn opens the file in write
mode for redirect from [:out, :err].
Before Ruby 2.2, it was opened in read mode.
=== Stdlib updates (outstanding ones only) === Stdlib updates (outstanding ones only)
* Find, Pathname * Find, Pathname

View file

@ -1595,6 +1595,18 @@ check_exec_redirect(VALUE key, VALUE val, struct rb_execarg *eargp)
key = check_exec_redirect_fd(key, 1); key = check_exec_redirect_fd(key, 1);
if (FIXNUM_P(key) && (FIX2INT(key) == 1 || FIX2INT(key) == 2)) if (FIXNUM_P(key) && (FIX2INT(key) == 1 || FIX2INT(key) == 2))
flags = INT2NUM(O_WRONLY|O_CREAT|O_TRUNC); flags = INT2NUM(O_WRONLY|O_CREAT|O_TRUNC);
else if (TYPE(key) == T_ARRAY) {
int i;
for (i = 0; i < RARRAY_LEN(key); i++) {
VALUE v = RARRAY_PTR(key)[i];
VALUE fd = check_exec_redirect_fd(v, 1);
if (FIX2INT(fd) != 1 && FIX2INT(fd) != 2) break;
}
if (i == RARRAY_LEN(key))
flags = INT2NUM(O_WRONLY|O_CREAT|O_TRUNC);
else
flags = INT2NUM(O_RDONLY);
}
else else
flags = INT2NUM(O_RDONLY); flags = INT2NUM(O_RDONLY);
perm = INT2FIX(0644); perm = INT2FIX(0644);

View file

@ -613,6 +613,17 @@ class TestProcess < Test::Unit::TestCase
} }
end end
def test_execopts_redirect_to_out_and_err
with_tmpchdir {|d|
ret = system(RUBY, "-e", 'STDERR.print "e"; STDOUT.print "o"', [:out, :err] => "foo")
assert_equal(true, ret)
assert_equal("eo", File.read("foo"))
ret = system(RUBY, "-e", 'STDERR.print "E"; STDOUT.print "O"', [:err, :out] => "bar")
assert_equal(true, ret)
assert_equal("EO", File.read("bar"))
}
end
def test_execopts_redirect_dup2_child def test_execopts_redirect_dup2_child
with_tmpchdir {|d| with_tmpchdir {|d|
Process.wait spawn(RUBY, "-e", "STDERR.print 'err'; STDOUT.print 'out'", Process.wait spawn(RUBY, "-e", "STDERR.print 'err'; STDOUT.print 'out'",