I bet your script /usr/local/bin/p4 is a shell script which
doesn't have a
"#!/bin/sh" line at the top, and that if you put
one in, it will work in
both cases.
When Ruby executes the command (under Unix/Linux anyhow) for
efficiency it
checks if the command contains a character which needs the
Unix shell to run
it. This includes ";". If not, it executes it
directory using one of the
exec(2) system calls. Otherwise it has to call
"/bin/sh" to run it, which
starts an extra process, and therefore is considerably
slower. Under most
Unixes, you need to have a "#!" line at the top of
scripts for exec() to
work.
If you run the script from the Unix shell, most shells will
automatically
run it as a shell script if exec() fails.
So perhaps the real "bug" is that Ruby should do
this also.
Cheers,
Mike Selig
----- Original Message -----
From: <noreply rubyforge.org>
To: <ruby-core ruby-lang.org>
Sent: Friday, December 15, 2006 8:59 AM
Subject: [ ruby-Bugs-7278 ] Kernel#system broken inside
Dir.chdir(&block) if
system command doesn't have shell characters
> Bugs item #7278, was opened at 2006-12-14 13:59
> You can respond by visiting:
> http://rubyforge.org/tracke
r/?func=detail&atid=1698&aid=7278&group_id=426
a>
>
> Category: Core
> Group: 1.8.x
> Status: Open
> Resolution: None
> Priority: 3
> Submitted By: Ryan Davis (zenspider)
> Assigned to: Nobody (None)
> Summary: Kernel#system broken inside
Dir.chdir(&block) if system command
doesn't have shell characters
>
> Initial Comment:
> I have a series of commands I'm trying to run that'll
only work if I'm in
the "p4" subdir. But system inside of a chdir is
borking unless I add a
semicolon to the command. The system/exec logic is overly
complex and hurts
my brain so I can't debug it:
>
> % ruby -v -e 'Dir.chdir("p4") { system
"/usr/local/bin/p4 info" }'
> ruby 1.8.5 (2006-08-25) [i686-darwin8.8.1]
> Perforce client error:
> Connect to server failed; check $P4PORT.
> TCP connect to perforce failed.
> perforce: host unknown.
>
> % ruby -v -e 'Dir.chdir("p4") { system
"/usr/local/bin/p4 info;" }' ###
<=== notice the semicolon
> ruby 1.8.5 (2006-08-25) [i686-darwin8.8.1]
> User name: ryand
> Client name: test1
> Client host: ewin-mac.limewire.com
> Client root: /Users/ryan/mirror/p4
> Current directory: /Users/ryan/mirror/p4
> Client address: 216.27.158.74:55857
> Server address:
dsl254-010-137.sea1.dsl.speakeasy.net:1666
> Server root: /Volumes/Users/perforce/root
> Server date: 2006/12/14 13:57:48 -0800 PST
> Server version:
P4D/DARWIN60CSPPC/2005.2.case_sensitive/90475 (2006/01/05)
> Server license: Ryan Davis/Zen Spider Software 30 users
(expires
2007/10/12)
>
>
>
------------------------------------------------------------
----------
>
> You can respond by visiting:
> http://rubyforge.org/tracke
r/?func=detail&atid=1698&aid=7278&group_id=426
a>
>
>
> --
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.1.409 / Virus Database: 268.15.19/587 -
Release Date: 14/12/06
>
>
|