- tmp = open(tmpfile, 'w')
- tmp.write(key + '\n')
- tmp.close()
- fp = os.popen('/usr/bin/ssh-keygen -l -f ' + tmpfile, "r")
- input = fp.readline()
- fp.close()
+ keygen = subprocess.Popen(['/usr/bin/ssh-keygen', '-l', '-f', '-'],
+ stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+ keygen.stdin.write(key + '\n')
+ keygen.stdin.close()
+ input = keygen.stdout.readline()
+ keygen.wait()