Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Store shell session/cmd.exe session in some object?

Reply
Thread Tools

Store shell session/cmd.exe session in some object?

 
 
Zach Dennis
Guest
Posts: n/a
 
      01-08-2004
I'd like to do something like:

mysession = SystemShell.new //Would I open a pipe? Would it be a IO.new?
dir_list = mysession.puts( "ls -al" ) //on Linux
dir_list = mysession.puts( "dir" ) //on Windows

and then further more do this:

mysession.puts( "ssh -l myname 127.0.0.1" )
mysession.puts( "cd /opt/webstar/etc/etc/" )
list = mysession.puts( "ls -al" )

And so on. Does this make sense. Basically I am looking to be able to keep a
session open with the system and receive it's output. This would prove
beneficial in the case that I ssh into several server and gather data from
each server in my script. Any ideas?

Thanks,


Zach




 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      01-08-2004

"Zach Dennis" <(E-Mail Removed)> schrieb im Newsbeitrag
news:(E-Mail Removed) m...
> I'd like to do something like:
>
> mysession = SystemShell.new //Would I open a pipe? Would it be a IO.new?
> dir_list = mysession.puts( "ls -al" ) //on Linux
> dir_list = mysession.puts( "dir" ) //on Windows


How about using Dir.entries( "." ) - this is more portable and likely
faster, too.

> and then further more do this:
>
> mysession.puts( "ssh -l myname 127.0.0.1" )
> mysession.puts( "cd /opt/webstar/etc/etc/" )
> list = mysession.puts( "ls -al" )
>
> And so on. Does this make sense. Basically I am looking to be able to

keep a
> session open with the system and receive it's output.


You mean "with the command processor". For simple usage you can resort to
IO.popen() (some caveats apply for windows). An example:

IO.popen( "cmd.exe", "r+" ) do |cmd|
Thread.new(cmd) do |io|
while line = io.gets
puts line
end
end

cmd.puts "dir"
cmd.puts "cd \\"
cmd.puts "dir"

sleep 3
end


Else there is expect for Ruby.
http://raa.ruby-lang.org/list.rhtml?name=ruby-expect

Regards

robert

 
Reply With Quote
 
 
 
 
Joel VanderWerf
Guest
Posts: n/a
 
      01-08-2004
Zach Dennis wrote:
> I'd like to do something like:
>
> mysession = SystemShell.new //Would I open a pipe? Would it be a IO.new?
> dir_list = mysession.puts( "ls -al" ) //on Linux
> dir_list = mysession.puts( "dir" ) //on Windows
>
> and then further more do this:
>
> mysession.puts( "ssh -l myname 127.0.0.1" )
> mysession.puts( "cd /opt/webstar/etc/etc/" )
> list = mysession.puts( "ls -al" )
>
> And so on. Does this make sense. Basically I am looking to be able to keep a
> session open with the system and receive it's output. This would prove
> beneficial in the case that I ssh into several server and gather data from
> each server in my script. Any ideas?


I've never used it, but does shell.rb in the standard lib do what you want?



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using subprocess module to launch a shell shell script that itselfforks a process Samuel A. Falvo II Python 0 10-08-2008 12:43 AM
Re: How to pass shell variable to shell script from python D'Arcy J.M. Cain Python 0 02-27-2008 01:56 PM
Re: How to pass shell variable to shell script from python Gerardo Herzig Python 1 02-27-2008 12:19 PM
Re: How to pass shell variable to shell script from python Christian Heimes Python 0 02-27-2008 10:53 AM
can I run unix shell command in the ModelSim shell? clinton__bill@hotmail.com VHDL 2 02-18-2005 10:04 PM



Advertisments