Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error : NameError: name 'subprocess' is not defined [closed]

Tags:

python

solaris

#!/usr/bin/python3 username = 'joe'  # generate passphrase pw_length = 6 phrase = subprocess.check_output(['pwgen', str(pw_length), '1']) phrase = phrase.decode('utf-8').strip()  dev_null = open('/dev/null', 'w') passwd = subprocess.Popen(['sudo', 'passwd', user], stdin=subprocess.PIPE,                           stdout=dev_null.fileno(),                           stderr=subprocess.STDOUT) passwd.communicate( ((phrase + '\n')*2).encode('utf-8') ) if passwd.returncode != 0:     raise OSError('password setting failed') 

how do i fix this error :

bash-3.00# python ./pass2.py Traceback (most recent call last):   File "./pass2.py", line 6, in ?     phrase = subprocess.check_output(['pwgen', str(pw_length), '1']) NameError: name 'subprocess' is not defined 
like image 784
munish Avatar asked Jan 29 '13 19:01

munish


1 Answers

Subprocess is a module. You need to import it.

Put this as the second line in your file: import subprocess

like image 68
jeffknupp Avatar answered Sep 18 '22 10:09

jeffknupp