Passing variables to a subprocess call [duplicate]

Try separating the values with commas:

subprocess.call(['useradd', '-m', '-g', _primarygroup, '-G', _secondarygroup, '-u', _userid, _username])

See http://docs.python.org/library/subprocess.html#subprocess.call – It takes an array where the first argument is the program and all other arguments are passed as arguments to the program.

Also don’t forget to check the return value of the function for a zero return code which means “success” unless it doesn’t matter for your script if the user was added successfully or not.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)