On Mar 21, 2:58 am, Dan Stromberg <[EMAIL PROTECTED]> wrote: > If you google a bit, I believe you'll find one or more python modules for > working with ssh. > > Also, if you want to roll your own, the easiest way to get around the > password requirement is to use ssh passwordless authentication using DSA > or RSA public/private keypairs: > > http://stromberg.dnsalias.org/~dstromberg/ssh-keys.html > > As far as why the code below doesn't open your "it_worked" file - exec > replaces the current process with the specified process - so the current > process effectively goes away on exec. > > On Thu, 20 Mar 2008 00:40:49 -0700, est wrote: > > Hello everyone. I am trying to write a bash/ssh wrapper in python so > > python scripts could interact with bash/ssh. > > > Because when input passwords to ssh it requires a tty rather than stdin > > pipe, so i have to use a pty module to do that. > > > I copied this snippet from this thread > >http://groups.google.com/group/comp.lang.python/browse_thread/ > > thread/6bbc3d36b4e6ff55/ > > > > > > > def rcmd(user, rhost, pw, cmd): > > #Fork a child process, using a new pseudo-terminal as the > > child's controlling terminal. > > pid, fd = os.forkpty() > > # If Child; execute external process > > if pid == 0: > > os.execv("/bin/ssh", ["/bin/ssh", "-l", user, rhost] + > > cmd) > > x=open("it_worked.txt", "w") #output a file for test > > x.write("xxx") > > x.close() > > #if parent, read/write with child through file descriptor else: > > pause() > > #Get password prompt; ignore > > os.read(fd, 1000) > > pause() > > #write password > > os.write(fd, pw + "\n") > > pause() > > res = '' > > #read response from child process > > s = os.read(fd,1 ) > > while s: > > res += s > > s = os.read(fd, 1) > > return res > > > As far as I can see the code is not working, when called the function > > rcmd() there is no file it_worked.txt spawned in the directory. I am > > n00b to POSIX, so anyone please give me some hint? what happened when > > os.forkpty()?- Hide quoted text - > > - Show quoted text -
Thanks for the reply! What's your recommandation for a bash wrapper? I am trying to implement some simple stuff which functions like ipython. -- http://mail.python.org/mailman/listinfo/python-list