Shell type

P

Panich, Alexander

------_=_NextPart_001_01C57802.107053AD
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Under Linux, by default, method Kernel.system(command) (backticks as
well) executes command in the subshell of SH type.

Is there a way to define another shell type (CSH for example) to execute
there, or not?

=20

Alex

=20


------_=_NextPart_001_01C57802.107053AD--
 
R

Robert Klemme

Under Linux, by default, method Kernel.system(command) (backticks as
well) executes command in the subshell of SH type.

Is there a way to define another shell type (CSH for example) to
execute there, or not?

You can always do:

ruby -e 'system "/bin/zsh", "-c", "ls bin/**/*.rb"'

But I'm sure there are other ways, too.

Kind regards

robert
 
A

Ara.T.Howard

Under Linux, by default, method Kernel.system(command) (backticks as
well) executes command in the subshell of SH type.

Is there a way to define another shell type (CSH for example) to execute
there, or not?

there shouldn't be, according to iso and posix c. you can always do something
like:

harp:~ > cat a.rb
def csh_system cmd
pipe = IO::popen 'csh', 'r+'
pipe.puts cmd
pipe.close_write
buf = pipe.read
pipe.close_read
status = $?.exitstatus
raise SystemCallError::new(status), cmd unless status == 0
buf
end

stdout = csh_system 'echo 42'
p stdout


harp:~ > ruby a.rb
"42\n"


i used to have csh interface in session, but took it out due to some issues
with stdout/stderr separation...

cheers.

-a
--
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| My religion is very simple. My religion is kindness.
| --Tenzin Gyatso
===============================================================================
 
J

Joel VanderWerf

Under Linux, by default, method Kernel.system(command) (backticks as
well) executes command in the subshell of SH type.

Is this really true?

irb(main):019:0> puts `pstree -a #{$$}`
irb ...
└─pstree -a 8921
=> nil
irb(main):020:0> Thread.new {system "/usr/local/bin/ruby", "-e", "puts
%{foo}; sleep 10"}
=> #<Thread:0xb7d64988 sleep>
irb(main):021:0> foo

irb(main):022:0* puts `pstree -a #{$$}`
irb ...
├─pstree -a 8921
└─ruby -e puts\040%{foo};\040sleep\04010
=> nil

This is linux, too. I don't see any sh invocation. It's not hidden by
pstree is it?
 
P

Pete Elmore

Joel said:
irb(main):022:0* puts `pstree -a #{$$}`
irb ...
├─pstree -a 8921
└─ruby -e puts\040%{foo};\040sleep\04010
=> nil

This is linux, too. I don't see any sh invocation. It's not hidden by
pstree is it?
I think the reason you don't see the shell is that it is exec()d,
otherwise this wouldn't work:
irb(main):082:0> `env | grep ^USER | sed s/$USER/me/`
=> "USER=me\n"
 
G

gwtmp01

Is this really true?

Hmm. I did some more poking. Without diving into the code too much
It looks like on most systems, Kernel.system emulates the behavior
of the Posix system() function instead of just calling it. Basically
if the command string has any characters that might need to be
interpreted by the shell (*;< and so on), then ruby fires up /bin/sh
to handle the command, otherwise Ruby just execs the program directly.

system "ls" # /bin/sh not started
system "ls *.rb" # /bin/sh started to handle filename expansion"

Note, that in both cases, Ruby is forking *first* and then starting
either the shell or the program.

If you use Kernel#exec then you have to managing forking in the
ruby code.


Gary Wright
 
N

nobu.nokada

Hi,

At Fri, 24 Jun 2005 03:59:38 +0900,
Joel VanderWerf wrote in [ruby-talk:146295]:
This is linux, too. I don't see any sh invocation. It's not hidden by
pstree is it?

Kernel#system doesn't invoke any sh if multiple strings
arguments are or a single string without shell metacharacters
is given. Instead, forks and execs directly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
474,174
Messages
2,570,940
Members
47,486
Latest member
websterztechnologies01

Latest Threads

Top