Project

General

Profile

Actions

Feature #4477

closed

Kernel:exec and backtick (`) don't work for certain system commands

Added by JWuttke (Joachim Wuttke) about 13 years ago. Updated almost 12 years ago.

Status:
Closed
Target version:
-
[ruby-core:35446]

Description

From documentation and common sense, I would expect that Kernel:exec and backtick (`) work for all kind of system commands. This is currently not the case.

~$ cat test1
echo success
~$ cat test2
#!/bin/sh
echo success
~$ chmod a+x test?
~$ ruby1.8 -e 'p test1'
-e:1: command not found: test1
""
~$ ruby1.9 -e 'p test1'
-e:1:in ``': Exec format error - test1 (Errno::ENOEXEC)
from -e:1:in <main>' ~$ ruby1.8 -e 'p test2`'
"success\n"
~$ ruby1.9 -e 'p `test2`'
"success\n"

This problem has been reported before (#3856: strange Kernel#exec behavior with bash's source command). As a workaround, it has been suggested to append a semikolon to the system command:

~$ ruby1.8 -e 'p test1;'
"success\n"
~$ ruby1.9 -e 'p test1;'
"success\n"

The report #3856 has been closed with the decision "not a bug".

This I cannot accept. For many years, I got used to run system commands through <cmd>. When it failed, I spent painfully long time to search for a bug in my Ruby code and in the system command before I realized the problem was due to an unexpected restriction of Ruby's exec/backtick.


Related issues 2 (0 open2 closed)

Related to Ruby master - Feature #2715: Optimization to avoid spawning shell in Kernel#system call should check for failure conditionsFeedbackActions
Related to Ruby master - Feature #4269: command with && should execute as shellClosednobu (Nobuyoshi Nakada)01/12/2011Actions
Actions #1

Updated by sorah (Sorah Fukumori) about 13 years ago

  • Tracker changed from Bug to Feature

=begin

=end

Updated by JWuttke (Joachim Wuttke) about 13 years ago

=begin
Sorry, Shota, I do not understand why you recategorized this issue as a Feature.

The current behaviour of <cmd> contradicts what the documentation says, and it offends common sense. In my understanding, this is clearly a Bug.
=end

Updated by sorah (Sorah Fukumori) about 13 years ago

=begin
I don't think this is Bug because that (Shebang less executing) is you shell's feature. not system's feature.

So this ticket should be Feature request.

=end

Updated by kosaki (Motohiro KOSAKI) about 13 years ago

=begin
2011/3/7 Shota Fukumori :

Issue #4477 has been updated by Shota Fukumori.

I don't think this is Bug because that (Shebang less executing) is you shell's feature. not system's feature.

No. it is POSIX spec. But, FWIW, This behavior have been changed
intentionally.So, I doubt the issue is a documentation fault.

Currently `` don't use shell if command line string don't have
following shell meta characters.
*?{}[]<>()~&|\$;'`"\n

But, Which documentation describe it?
=end

Updated by akr (Akira Tanaka) about 12 years ago

  • Description updated (diff)

Updated by mame (Yusuke Endoh) about 12 years ago

  • Status changed from Open to Assigned
  • Assignee set to kosaki (Motohiro KOSAKI)

Updated by mame (Yusuke Endoh) about 12 years ago

  • Assignee changed from kosaki (Motohiro KOSAKI) to akr (Akira Tanaka)

Updated by mrkn (Kenta Murata) about 12 years ago

  • Description updated (diff)

Updated by akr (Akira Tanaka) almost 12 years ago

  • Status changed from Assigned to Closed

The feature of shell, invoke /bin/sh after ENOEXEC, is implemented
at r33009 of Ruby.

So this example works now as follows.

% cat test1
echo success
% chmod a+x test1
% ./ruby -ve 'p ./test1'
ruby 2.0.0dev (2012-06-04 trunk 35911) [x86_64-linux]
"success\n"

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0