0

Is it possible to prevent subprocess.popen from showing prompts in the terminal?

Attempting to map a drive but would like to read the prompt for credentials in the script rather than display them to the terminal. The idea being I can carry out actions based on the response.

I am aware the use of shell is frowned upon when using string based commands (for obvious reasons), however I'm controlling the input so am happy with the risk for testing purposes.

I was under the impression that all stdout (interaction) would be parsed into the output_null variable. Instead I am still getting the prompt in the terminal (as illustrated below). I'm either miss understanding how the streams work or I'm missing something. Can anyone enlighten me please

command = "mount -t smbfs //{s}/SYSVOL {m}".format(s=server, m=temp_dir)
p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output_null = p.communicate()[0]
if "Password for" in output_null:
    print 'awdaa'

Terminal Shows

Password for 192.168.1.111:
iNoob
  • 1,375
  • 3
  • 19
  • 47
  • Try use `mount -t smbfs -o username=[username],password=[password] ...` to specify username and password directly. Or you need to simulate a tty like this (http://stackoverflow.com/a/30143013/2644759) to get things work. – Philip Tzou Aug 20 '16 at 00:12
  • @PhilipTzou, yip I know how to specify the options. This check is specificly testing if anonymous access is allowed. I'm sure I have tried PIPE'ing all the streams already. However I will try it again and get back to you with feed back – iNoob Aug 20 '16 at 06:04
  • @PhilipTzou, yip same results. The terminal is prompted for a Password – iNoob Aug 20 '16 at 06:06

0 Answers0