Hi all,
I have been trying to use python to automate a sequence of processes on my computer, one of which is starting a hosted network. I have used subprocess to interact with command prompt (windows 10), and am struggling to pass sequential commands. I am trying to first send the administrator password, since it needs to run with administrator rights, and then netsh commands to set up and run a hosted network. Here is what i have come up with so far:
main():
prog = sp.Popen(['runas', '/noprofile', '/user:Administrator', 'CMD.exe'], stdin=sp.PIPE, stdout=sp.PIPE, stderr=sp.PIPE)
data = prog.stdout.read() #get cmd output
data = data.decode('utf-8') #decode from byte to string
print(data)
prog.stdout.seek(0) #set read position to start
command = 'adminpasswd'
command = command.encode('utf-8') #encode pwd to byte
prog.stdin.write(command) #write pwd to cmd
data = prog.stdout.read() #get cmd output
data = data.decode('utf-8') #decode from byte to string
print(data)
main()
The first read attempt works fine, it prints the "enter administrator password" prompt. However, any subsequent commands i send and then try to read the output of return blank. Ive tried the command 'netsh wlan show drivers' since I know this will return something to read, yet my program still reads ''. Am I sending the commands correctly, or am I just reading in the wrong places?
Many thanks