我正在尝试使用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:如何调试这种场景?在
我在当地做过:
我要问你的问题是:当你对psexec做同样的操作时,它还能工作吗?在
使用字符串
connection_string
而不是列表可能会有问题。 尝试:添加Popen(…,shell=True)
使用列表。在
相关问题 更多 >
编程相关推荐