import sys port = sys.argv[1] passwd = sys.argv[2] import subprocess p = subprocess.Popen(['vncpasswd','-f'],stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE) (encpass,stderr) = p.communicate(passwd) p = subprocess.Popen(['vncviewer','-autopass','localhost::{}'.format(port)],stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE) p.communicate(passwd)