I want to execute a subprocess in python, and the subprocess require an argument to specify a password. By default, everyone who can login this machine can get the password with the ps
utility when my subprocess is running.
And I know Popen has an __executable__
param, which can hide the real program name, but cannot hide the password argument of the subprocess.
How can I hide my password?
PS: I running on linux.
I don't think you can do that for subprocess, but there is a library to do it from subprocess: http://code.google.com/p/py-setproctitle/
The method is specific to each OS; some systems don't support that at all. If possible, give password to the subprocess by other means (e.g. via stdin pipe).
subprocess
doesn't expose an API to do that. I'd recommend passing the password to the command using an environment variable:
subprocess.check_call('command --password="$PASSWORD"', shell=True,
env=dict(os.environ, PASSWORD=password))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With