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

Discussion in 'Ruby' started by Zach Dennis, Jan 8, 2004.

  1. Zach Dennis

    Zach Dennis Guest

    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
     
    Zach Dennis, Jan 8, 2004
    #1
    1. Advertising

  2. "Zach Dennis" <> schrieb im Newsbeitrag
    news:...
    > 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
     
    Robert Klemme, Jan 8, 2004
    #2
    1. Advertising

  3. 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?
     
    Joel VanderWerf, Jan 8, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Achim Domma (Procoders)

    read input for cmd.Cmd from file

    Achim Domma (Procoders), Jun 3, 2005, in forum: Python
    Replies:
    2
    Views:
    8,079
    Peter Otten
    Jun 3, 2005
  2. Sarir Khamsi

    Interpreter-like help in cmd.Cmd

    Sarir Khamsi, Jun 9, 2005, in forum: Python
    Replies:
    4
    Views:
    379
    Bengt Richter
    Jun 26, 2005
  3. =?ISO-8859-1?Q?Sch=FCle_Daniel?=

    [exec cmd for cmd in cmds]

    =?ISO-8859-1?Q?Sch=FCle_Daniel?=, Mar 8, 2006, in forum: Python
    Replies:
    3
    Views:
    391
    Scott David Daniels
    Mar 8, 2006
  4. Sol Linderstein
    Replies:
    3
    Views:
    191
    Matt Garrish
    Jun 18, 2004
  5. alex
    Replies:
    4
    Views:
    403
Loading...

Share This Page