I am writing a python script as below:
#!/usr/bin/python import os, subprocess env = os.environ.copy() env['PASSWD'] = "hello jian" retcode = subprocess.call("smbclient -L //10.60.1.11 -U Mikejian"),env=env) print retcode
how I execute it, it works fine, get retcode is 0, you know, I pass the password as an environment variable, so python will not ask me about it.
this is normal.
Now I want to move this code to MoinMoin (wiki engine) code. which is in the User class, as a function below
def _validateSMBPassword(self, username, password): debug("call _validateSMBPassword %s:%s " % (username, password)) import subprocess, os, shlex cmd = "sudo smbclient -L //%(server)s -U %(user)s" cmd = cmd % { 'server' : "10.60.1.11", 'user' : "Mikejian", } env = os.environ.copy() env['PASSWD'] = "hello jian" retcode = subprocess.call("smbclient -L //10.60.1.11 -U Mikejian",env=env,shell=True) debug("retcode:%d" % retcode) if retcode == 0: return True, True return False, False
in this case, I always got retcode equal to 1, not 0, it seemed that env did not pass the PASSWD environment variable.
Could you tell me why? and any solution?
source share