I am trying to get my basic python script to open and to write to and read to a cmd in order to allow it to send commands into noxplayer. I am trying to use sub processes and have discovered and read about using PIPES and not using them. Either way I can get it to send input with it resulting in a series of different breakpoints. Here are 2 examples of code I have tried.
class bot:
def __init__(self, num):
self.num = num
def start(self):
#open app and command prompt
androidArg1 = "C:/Program Files (x86)/Nox/bin/Nox.exe"
androidArg2 = "-clone:Nox_" + str(self.num)
androidArgs = [androidArg1, androidArg2]
cmdArg1 = 'cmd'
cmdArgs = [cmdArg1]
self.app = subprocess.Popen(androidArgs)
self.cmd = subprocess.Popen(cmdArgs, shell=True)
self.cmd.communicate(input="cd C:/Program Files (x86)/Nox/bin")
while True:
self.devices = self.cmd.communicate(input="nox_adb devices")
print(self.devices)
is printing out C:\Users\thePath> but never finishes the first communication
class bot:
def __init__(self, num):
self.num = num
def start(self):
#open app and command prompt
androidArg1 = "C:/Program Files (x86)/Nox/bin/Nox.exe"
androidArg2 = "-clone:Nox_" + str(self.num)
androidArgs = [androidArg1, androidArg2]
cmdArg1 = 'cmd'
cmdArgs = [cmdArg1]
self.app = subprocess.Popen(androidArgs)
self.cmd = subprocess.Popen(cmdArgs, stdin=PIPE, stderr=PIPE, stdout=PIPE, universal_newlines=True, shell=True)
stdout, stderr = self.cmd.communicate()
stdout, stderr
self.cmd.communicate(input="cd C:/Program Files (x86)/Nox/bin")
while True:
self.devices = self.cmd.communicate(input="nox_adb devices")
print(self.devices)
throws
Cannot send input after starting communication
What am I doing wrong and what is the right way to go about doing this?