[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Is it possible to make system use bash instead of sh?

Wai Tsang

4/25/2007 3:18:00 PM

Hi,

Does anyone know if it is possible to use bash instead of sh as the
default shell when "system" is executed?

For example, system("java --version") is executing java --version in sh,
instead of bash, which can be a problem when I tried to do error
redirection.

--
Posted via http://www.ruby-....

12 Answers

Björn Paetzel

4/25/2007 3:43:00 PM

0

Wai Tsang schrieb:
> Hi,
>
> Does anyone know if it is possible to use bash instead of sh as the
> default shell when "system" is executed?

System() should always call /bin/sh (on a POSIX compliant system), but
of course you could still have sh call bash, like this:

system("bash java --version")

Robert Klemme

4/25/2007 3:57:00 PM

0

On 25.04.2007 17:43, Björn Paetzel wrote:
> Wai Tsang schrieb:
>> Does anyone know if it is possible to use bash instead of sh as the
>> default shell when "system" is executed?
>
> System() should always call /bin/sh (on a POSIX compliant system),

Where did you get that information from?

> but
> of course you could still have sh call bash, like this:
>
> system("bash java --version")

Yes, of course.

robert

Robert Dober

4/25/2007 4:04:00 PM

0

On 4/25/07, Wai Tsang <simotsa@gmail.com> wrote:
> Hi,
>
> Does anyone know if it is possible to use bash instead of sh as the
> default shell when "system" is executed?
>
> For example, system("java --version") is executing java --version in sh,
> instead of bash, which can be a problem when I tried to do error
> redirection.
>
> --
> Posted via http://www.ruby-....
>
If bash is in your path you can do
system("bash -c \"java -version\"")
else you just have to put the full path, this works even on Windows :)

Of course that is not exactly what you want, you would like to tell
Kernel or whatever other object that wants to hear that kind of
message: "You are going to use /bin/bash for system from now on".
So I went digging the code, no such luck, I just could not find the
definition of Kernel#system :(
neither with rb_define_method.*system
nor with def\s*system
and even less with
alias\s*system
or
rb_alias.*system
Hope that somebody more learned will help us out here.

Cheers
Robert
>


--
You see things; and you say Why?
But I dream things that never were; and I say Why not?
-- George Bernard Shaw

Gary Wright

4/25/2007 4:46:00 PM

0


On Apr 25, 2007, at 12:00 PM, Robert Klemme wrote:

> On 25.04.2007 17:43, Björn Paetzel wrote:
>> Wai Tsang schrieb:
>>> Does anyone know if it is possible to use bash instead of sh as the
>>> default shell when "system" is executed?
>> System() should always call /bin/sh (on a POSIX compliant system),
>
> Where did you get that information from?

This behavior with respect to the Single Unix
Specification is documented at:

http://www.opengroup.org/onlinepubs/007908799/xsh/s...



Gary Wright




Brian Candler

4/25/2007 6:41:00 PM

0

On Thu, Apr 26, 2007 at 12:18:04AM +0900, Wai Tsang wrote:
> Does anyone know if it is possible to use bash instead of sh as the
> default shell when "system" is executed?

system() with multiple arguments bypasses the shell. So try:

system("/bin/bash", "-c", "java --version")

Booker C. Bense

4/25/2007 8:06:00 PM

0

-----BEGIN PGP SIGNED MESSAGE-----

In article <335e48a90704250904y7c06bcb5s74b34cd86d92860e@mail.gmail.com>,
Robert Dober <robert.dober@gmail.com> wrote:
>On 4/25/07, Wai Tsang <simotsa@gmail.com> wrote:
>
>Of course that is not exactly what you want, you would like to tell
>Kernel or whatever other object that wants to hear that kind of
>message: "You are going to use /bin/bash for system from now on".
>So I went digging the code, no such luck, I just could not find the
>definition of Kernel#system :(
>neither with rb_define_method.*system
>nor with def\s*system
>and even less with
>alias\s*system
>or
>rb_alias.*system
>Hope that somebody more learned will help us out here.
>

_ Ruby uses the underlying C exec call and any system that does
not use /bin/sh is severely broken. It's part of the POSIX
standard. If you want bash, then use the multi-arg form of the
command which bypasses shell interpretation entirely.

If you want the gory details look in process.c

rb_f_system

_ Booker C. Bense

-----BEGIN PGP SIGNATURE-----
Version: 2.6.2

iQCVAwUBRi+0jmTWTAjn5N/lAQEwgAP/SrYiy/UhXzHGJ4G4FJwP9XV72ogYvfbO
CyhpNvaMdeBJEVp7lGl+Dw84fLlsQY6Dh9HBnzsyLv0vkpnOHByeQc+GVB9KdMYh
C91ilHEPXQdI2QJPlMmnUh4H+fvRs5NgoNXIORhE4lnbsVXBDIcl73mXY0kHU82z
fL4OcNifcnM=
=EJLT
-----END PGP SIGNATURE-----

Chad Perrin

4/25/2007 8:24:00 PM

0

On Thu, Apr 26, 2007 at 01:46:25AM +0900, Gary Wright wrote:
>
> This behavior with respect to the Single Unix
> Specification is documented at:
>
> http://www.opengroup.org/onlinepubs/007908799/xsh/s...

Standards like the Single Unix Specification (and the LSB, and so on)
should be used as reasons for standardized behavior in a distributed
OS, but they aren't really relevant to customized installs. If an end
user wants to configure a system differently from the standard, that's
his/her business.

--
CCD CopyWrite Chad Perrin [ http://ccd.ap... ]
Leon Festinger: "A man with a conviction is a hard man to change. Tell
him you disagree and he turns away. Show him facts and figures and he
questions your sources. Appeal to logic and he fails to see your point."

Ari Brown

4/25/2007 8:30:00 PM

0


On Apr 25, 2007, at 11:18 AM, Wai Tsang wrote:

> Hi,
>
> Does anyone know if it is possible to use bash instead of sh as the
> default shell when "system" is executed?
Whenever 'system' is executed? Not sure about that. But what you
might be able to do is have a new file that stores code which defines
'system2', and you could include that. It might be something like:

def system2(command)
system 'bash'
system '#{command}
end

Of course, i have no clue (yet) how to use #{stuff} in my code, so
any help would automatically be worthy of worship.

Oh, and same with having two parameters in 'do' commands. Help? Please?

HTH
-------------------------------------------------------|
~ Ari
crap my sig won't fit


Robert Dober

4/25/2007 9:34:00 PM

0

On 4/25/07, Booker C. Bense
<snip>
> If you want the gory details look in process.c
>
> rb_f_system

Thx a lot, that's what I was looking for...
>
> _ Booker C. Bense
>
> -----BEGIN PGP SIGNATURE-----
> Version: 2.6.2
>
> iQCVAwUBRi+0jmTWTAjn5N/lAQEwgAP/SrYiy/UhXzHGJ4G4FJwP9XV72ogYvfbO
> CyhpNvaMdeBJEVp7lGl+Dw84fLlsQY6Dh9HBnzsyLv0vkpnOHByeQc+GVB9KdMYh
> C91ilHEPXQdI2QJPlMmnUh4H+fvRs5NgoNXIORhE4lnbsVXBDIcl73mXY0kHU82z
> fL4OcNifcnM=
> =EJLT
> -----END PGP SIGNATURE-----
>
>


--
You see things; and you say Why?
But I dream things that never were; and I say Why not?
-- George Bernard Shaw

Gary Wright

4/25/2007 9:52:00 PM

0


On Apr 25, 2007, at 4:24 PM, Chad Perrin wrote:

> On Thu, Apr 26, 2007 at 01:46:25AM +0900, Gary Wright wrote:
>>
>> This behavior with respect to the Single Unix
>> Specification is documented at:
>>
>> http://www.opengroup.org/onlinepubs/007908799/xsh/s...
>
> Standards like the Single Unix Specification (and the LSB, and so on)
> should be used as reasons for standardized behavior in a distributed
> OS, but they aren't really relevant to customized installs. If an end
> user wants to configure a system differently from the standard, that's
> his/her business.

I didn't see anyone claiming differently. I certainly wasn't. I just
perceived the question as a desire for information about the standard.