我正在尝试使用psexec连接到远程计算机并执行命令提示符. 一旦打开这个会话,我想运行多个命令,如mkdir、del等。我面临的问题是,我只能运行一个命令,子进程是communicate close the pipe。有什么办法可以完成吗?在from subprocess import Popen, PIPE, STDOUT
class WsRPC():
def __init__(self):
self.rpc_exec_path = r'C:\SysinternalsSuite\psexec.exe'
self.user = 'administrator'
self.ip = '172.xxx.xxx.xxx'
self.password = 'XxXxXxXx'
self.session = ''
def wsConnect(self):
pass
def runCommand(self):
try:
self.session = Popen([self.rpc_exec_path, '\\\\' + self.ip, '-u',
self.user, '-p', self.password, 'cmd.exe'],
stdin = PIPE,stdout = PIPE,stderr = PIPE,
shell = True)
command = 'cmd.exe /c dir'
self.session.stdin.write('dir/r/n')
strout, strerr = self.session.communicate()
print strout
print strerr
except Exception,e:
print str(e)
obj = WsRPC()
obj.runCommand()
我运行此代码时得到以下o/p-
^{pr2}$
看来我的“dir”不起作用了。在
PS:如何调试这种场景?在