0

I did not find a direct answer to this question, so, asking it in this forum. My question is this - I am using python 2.6.6 version, and using subprocess.popen command to call into a script with some arguments. Some of the arguments are passwords. When I directly use this:

args = shlex.split(cmd)
f = open("a.txt", "a+");
proc = subprocess.Popen(args, stderr=f, stdout=f)
proc.communicate()
retcode = proc.returncode

The command gets executed fine, but I see that ps -ef shows the passwords in clear text. Is there a way to handle this in subprocess api? I have multiple passwords to be passed.

Thanks!

coder
  • 129
  • 1
  • 1
  • 10
  • pass them in standard input, not as arguments – Jean-François Fabre Oct 25 '18 at 12:48
  • 1
    To elaborate sightly on @Jean-FrançoisFabre 's answer. You must first examine how your `cmd` can accept password to be input. Surely there must be another way than passing them as arguments or they would always be detectable with a `ps -ef` call, and it has nothing to do with using Python. – JohanL Oct 26 '18 at 15:19
  • Thanks! You were right, @JohanL. I was passing passwords to subprocess in clear text. – coder Oct 29 '18 at 12:12
  • You can also pass in password as environment variables, in addition to `stdin` . – whatacold Jun 23 '19 at 14:56

0 Answers0