Entering password in shell

Discussion in 'Ruby' started by Eric C., Dec 1, 2010.

  1. Eric C.

    Eric C. Guest

    HI:

    I'm trying to run a shell to install a gem:

    PTY.spawn("sudo gem install #{gem} --local 2>&1") do |stdin,stdout,pid|
    stdout.write("#{pass}\n")
    puts stdin.read.lstrip #write output to screen
    end

    This works fine if the password is correct. However, if the password is
    not correct it hangs. I've tried this line too:

    stdout.write("#{pass}\n\n\n\n\n\n")

    to try to get it to terminate, but it still hangs. Is there a way to
    enter passwords into the command line or enter them ahead of time?

    Thanks,
    Eric

    --
    Posted via http://www.ruby-forum.com/.
     
    Eric C., Dec 1, 2010
    #1
    1. Advertising

  2. On Tue, Nov 30, 2010 at 7:07 PM, Eric C. <> wrote:
    > HI:
    >
    > I'm trying to run a shell to install a gem:
    >
    > PTY.spawn("sudo gem install #{gem} --local 2>&1") do |stdin,stdout,pid|
    > =A0stdout.write("#{pass}\n")
    > =A0puts stdin.read.lstrip =A0#write output to screen
    > end
    >
    > This works fine if the password is correct. =A0However, if the password i=

    s
    > not correct it hangs. =A0I've tried this line too:
    >
    > =A0stdout.write("#{pass}\n\n\n\n\n\n")
    >
    > to try to get it to terminate, but it still hangs. =A0Is there a way to
    > enter passwords into the command line or enter them ahead of time?
    >
    > Thanks,
    > Eric


    sudo -v will prompt the user for the password ahead of time.
     
    Eric Christopherson, Dec 4, 2010
    #2
    1. Advertising

  3. Eric C.

    Eric C. Guest

    Hi:

    Thanks for your response. However, I don't think that using the -v
    option works.

    I may not need to do it anyway because the process I was trying to do
    was install a gem on my local machine:

    `sudo gem install xxxx.gem`

    I found that you can require rake, and do a better job:

    require 'rake'

    Rake::GemPackageTask.new(spec) do |pkg|
    pkg.need_zip = true
    pkg.need_tar = true
    end

    I don't know how this works, I'm trying it now. Thanks for help,

    Eric

    --
    Posted via http://www.ruby-forum.com/.
     
    Eric C., Dec 5, 2010
    #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. otf
    Replies:
    5
    Views:
    3,749
    Roedy Green
    Nov 29, 2005
  2. Tuvas

    Password entering system

    Tuvas, Mar 10, 2006, in forum: Python
    Replies:
    4
    Views:
    368
    Tuvas
    Mar 10, 2006
  3. rodrigo
    Replies:
    3
    Views:
    776
    Ryan Ginstrom
    Oct 15, 2007
  4. AAaron123
    Replies:
    2
    Views:
    2,197
    AAaron123
    Jan 16, 2009
  5. douxin
    Replies:
    5
    Views:
    128
    Chris Angelico
    Jan 18, 2013
Loading...

Share This Page