所以我遇到了一个问题,现在确定我做错了什么。我正在使用python 2.4和子进程模块。这与我的django网站集成在一起。我有一个表单,要求一些用户输入,它将它放入一个文件然后启动脚本与文件所在的目录。
如果我对字符串中的目录进行硬编码,它将正常工作,并输出wlst脚本,如果我不这样做它将无法工作,只是连接并认为它已完成。
仍然没有任何信息。为什么。该脚本工作正常的命令行,甚至从普通的python代码。我唯一能说的就是变量。
代码:
if form.is_valid():
env = form.cleaned_data['env']
user = form.cleaned_data['user']
group = form.cleaned_data['group']
role = form.cleaned_data['role']
id = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(6))
root = "/opt/tools/Mapper/output/webui/%s" % (id)
if not os.path.exists(root):
os.makedirs(root)
output = open(root+"/mapping.out", 'w')
if (user):
user_stg = "User:"+user+":"
password = User.objects.filter(user__contains=user).values('password')
password_f = open(root+"/passwords.out", 'w')
password_out = "%s:%s" % (user, password[0]['password'].encode('ascii'))
password_f.write(password_out)
if (group):
grp_stg = "GroupName:"+group+":"
if(role):
role_stg = "RoleName:"+role
out_stg = user_stg+grp_stg+role_stg
output.write(out_stg+"\n")
command = "/opt/tools/Mapper/bin/wlst /opt/tools/Mapper/bin/creator -e ldap.dev -s pacdcespopsa1:7001 -o /opt/tools/Mapper/output/webui/JBHSMN"
args = shlex.split(command)
print args
resp = HttpResponse(command_output(args));
def command_output(args):
import subprocess
return subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
此代码与可变驱动的代码之间的唯一区别是我有
command = "/opt/tools/Mapper/bin/wlst /opt/tools/Mapper/bin/creator -e ldap.dev -s pacdcespopsa1:7001 -o %s" % (root)