does popen3 thow exceptions? how to erro check?

Rene Salmon rsalmon at tulane.edu
Thu Aug 16 14:52:20 EDT 2001


Hello,

First I have spent lots of time on this and looked at the mailing list
and the python site and I am still not clear on how to do this so I am
posting this message.

I am trying to write a python script to change or add a users samba
passwd
this can be done by running "smbpasswd -a -s"

man smbpasswd
 -s   This option causes smbpasswd to be silent (i.e. not
               issue prompts) and to read it's old and new passwords
               from standard input, rather than from /dev/tty (like
               the passwd(1) program does). This option is to aid
               people writing scripts to drive smbpasswd



This python code seems to work great it does indeed change the samba
password or add the user if the user does not exist.

         #run smbpasswd to add user to samba
        (child_stdin,child_stdout,child_stderr)=os.popen3("smbpasswd
-a -s","t")
        
        child_stdin.write(new_passwd)
        child_stdin.write(new_passwd)
        child_stdin.close()
        child_stderr.close()
        child_stdout.close()
    

How do I check this code to make sure that there was no error when
running it??
say I mistype 

(child_stdin,child_stdout,child_stderr)=os.popen3("badcommand -a
-s","t")

I the program still completes and produces no errors. I tryed
enclosing the code
in a try: and except: block but that did not work   

I also tried getting the file descriptor from the file objects
child_stdin
using fileno() and checking the status of the file descriptor with
fstat() but that always returned true that file descriptor always gets
created.

any ideas on how to error check popen3?

Thank you for any help or hints you can give me
please respond to me as I am not subscribed to the list.

Rene



More information about the Python-list mailing list