Feature #4477


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

Added by JWuttke (Joachim Wuttke) over 11 years ago. Updated about 10 years ago.

Target version:


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
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`'
~$ ruby1.9 -e 'p `test2`'

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;'
~$ ruby1.9 -e 'p test1;'

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

Also available in: Atom PDF