Regarding Popen in python

Hi.. I am using python script for running other script present in apache bin dir and i am using Popen function to run.

The apache script which i want to run is htpasswd which takes username as input and asks for password two times.

i am able to run the script but before i am entering the password ...the prompt is going for retype the password

Please find the function of code i have attached.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
def createpassword(config, options, username):
    out = file( config["logs_dir"] + "/httpd.log", "a+" )
    passwd = config["apache_dir"] + "/bin/htpasswd"
    passwd_dir = config["passwd_dir"] + "/.htpasswd"
    args = [passwd, "-c", passwd_dir, username]
    proc = Popen(args,env=os.environ, stdin=PIPE, stdout=PIPE, stderr=STDOUT )
    log( "create passwd args:", args )
    return proc
Open in New Window Select All

Solution: Regarding Popen in python

The reason for mixing the output from the passwd code and your script probably is that the Popen instance run in the separate process, and you did not say to wait for the result.

Try to call the wait method of the Popen or call the helper function call() with the same arguments. See below. (Warning, I did not try -- just my qualified guess.)
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
    ...
    returncode = Popen(args,env=os.environ, stdin=PIPE, stdout=PIPE, stderr=STDOUT ).wait()
    log( "create passwd args:", args )
    return returncode
 
    ## or use the equivalent...
 
    returncode = subprocess.call(args,env=os.environ, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
    log( "create passwd args:", args )
    return returncode
Open in New Window Select All