Issue #7489 has been reported by jcaesar (Julius Caesar). ---------------------------------------- Bug #7489: Kernel.spawn sometimes executes string directly https://bugs.ruby-lang.org/issues/7489 Author: jcaesar (Julius Caesar) Status: Open Priority: Normal Assignee: Category: Target version: ruby -v: ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-linux] Kernel.spawn throws an exception in certain cases where it shouldn't. It seems to attempt to execute the command directly, rather than passing it to the shell. See the demo script below. What should happen, when I run this script, is that both assertions should fail, and there should be an error message from the testing framework about each test. What actually happens is that both tests pass and the test framework reports success. #------------------------------- require 'test/unit' class TestSpawn < Test::Unit::TestCase #> either command would work fine if executed # in the shell. def test1 assert_raises(Errno::ENOENT) { spawn ':' } end def test2 assert_raises(Errno::ENOENT) { spawn 'a=b true' } end end #------------------------------- My compiler is GCC, and the output of "gcc --version" is: gcc-4.4.real (Debian 4.4.5-8) 4.4.5 Copyright (C) 2010 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Please note that I have attached my rbconfig.rb file.
on 2012-12-01 18:58
on 2012-12-06 09:18
2012/12/2 jcaesar (Julius Caesar) <redmine@ruby-lang.org>: > Bug #7489: Kernel.spawn sometimes executes string directly > https://bugs.ruby-lang.org/issues/7489 > Kernel.spawn throws an exception in certain cases where it shouldn't. > It seems to attempt to execute the command directly, rather than passing > it to the shell. Ruby invokes simple commands, command line without meta characters, directly without shell. This behavior is inherited from Perl. We cannot remove the behavior because people assumes pid returned from Kernel.spawn (and IO#pid for IO.popen) is the pid of invoked simple command. If we use always invoke a command via shell, people will find they cannot kill the command because returned pid will be the pid of shell, not the command. However, Ruby 2.0 refines the algorithm to use shell or not. So, your example will fail as you expected.
on 2012-12-10 22:05
Issue #7489 has been updated by jcaesar (Julius Caesar). Thanks for the response. My only comment is that the behaviour you describe is not documented (unless I'm missing something), and should be. By the way, I was unaware of your reply until a short time ago. For some reason, I was never notified by email. ---------------------------------------- Bug #7489: Kernel.spawn sometimes executes string directly https://bugs.ruby-lang.org/issues/7489#change-34593 Author: jcaesar (Julius Caesar) Status: Open Priority: Normal Assignee: Category: Target version: ruby -v: ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-linux] Kernel.spawn throws an exception in certain cases where it shouldn't. It seems to attempt to execute the command directly, rather than passing it to the shell. See the demo script below. What should happen, when I run this script, is that both assertions should fail, and there should be an error message from the testing framework about each test. What actually happens is that both tests pass and the test framework reports success. #------------------------------- require 'test/unit' class TestSpawn < Test::Unit::TestCase #> either command would work fine if executed # in the shell. def test1 assert_raises(Errno::ENOENT) { spawn ':' } end def test2 assert_raises(Errno::ENOENT) { spawn 'a=b true' } end end #------------------------------- My compiler is GCC, and the output of "gcc --version" is: gcc-4.4.real (Debian 4.4.5-8) 4.4.5 Copyright (C) 2010 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Please note that I have attached my rbconfig.rb file.
on 2013-02-17 06:35
Issue #7489 has been updated by ko1 (Koichi Sasada). Category set to DOC Assignee set to akr (Akira Tanaka) Target version set to next minor Akr-san, could you add a documentation? ---------------------------------------- Bug #7489: Kernel.spawn sometimes executes string directly https://bugs.ruby-lang.org/issues/7489#change-36384 Author: jcaesar (Julius Caesar) Status: Open Priority: Normal Assignee: akr (Akira Tanaka) Category: DOC Target version: next minor ruby -v: ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-linux] Kernel.spawn throws an exception in certain cases where it shouldn't. It seems to attempt to execute the command directly, rather than passing it to the shell. See the demo script below. What should happen, when I run this script, is that both assertions should fail, and there should be an error message from the testing framework about each test. What actually happens is that both tests pass and the test framework reports success. #------------------------------- require 'test/unit' class TestSpawn < Test::Unit::TestCase #> either command would work fine if executed # in the shell. def test1 assert_raises(Errno::ENOENT) { spawn ':' } end def test2 assert_raises(Errno::ENOENT) { spawn 'a=b true' } end end #------------------------------- My compiler is GCC, and the output of "gcc --version" is: gcc-4.4.real (Debian 4.4.5-8) 4.4.5 Copyright (C) 2010 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Please note that I have attached my rbconfig.rb file.
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.