Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python subprocess.Popen hide real "display name"

Tags:

python

popen

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.

like image 600
bones7456 Avatar asked Jul 09 '12 11:07

bones7456


2 Answers

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).

like image 178
hamstergene Avatar answered Sep 27 '22 23:09

hamstergene


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))
like image 26
ecatmur Avatar answered Sep 27 '22 22:09

ecatmur