Pass variable to subprocess call in python -
i trying pass variables raw_input subprocess command. new python. appreciated.
#!/usr/bin/python import subprocess print "\nwhat user name" username = str(raw_input('username: ')) print "\nwhat user id" userid = int(raw_input('enter user id: ')) print "\nwhat user\'s primary group?" primarygroup = int(raw_input('enter group: ')) print "\nwhat user\'s secondary group?" secondarygroup = int(raw_input('enter group: ')) subprocess.call(['useradd' '-m' '-g' _primarygroup '-g' _secondarygroup '-u' _userid _username]) print"\nthe user has been added"
try separating values commas:
subprocess.call(['useradd', '-m', '-g', _primarygroup, '-g', _secondarygroup, '-u', _userid, _username])
see http://docs.python.org/library/subprocess.html#subprocess.call - takes array first argument program , other arguments passed arguments program.
also don't forget check return value of function 0 return code means "success" unless doesn't matter script if user added or not.
Comments
Post a Comment