From: MonkeeSage Date: 2007-12-01T17:45:00+09:00 Subject: Re: run system command as user On Nov 30, 7:56 pm, Trey wrote: > I'm in need of running a system command as another user than the user > that is executing the ruby script. Is this possible? Can I execute > su (and somehow supply the correct password), then run the command? Here is a naive version using the built-in pty extension (*nix only, but since you mention su, I assume that's not a problem)... require "pty" require "expect" cmd = "sleep 1; sudo -u someuser ls 2>&1" PTY.spawn(cmd) { | stdin, stdout, pid | stdin.expect(/Password:|/) { | result, pass | stdout.write("secret_password\n") if pass } puts stdin.read } Regardsm Jordan