我要执行一个pskill.exe命令。 在dos提示符下尝试过: C: \Users\JohanSA\Documents\EclipseWorkspace\ProdataATFBASE\src\resources\pskill.exe\本地主机-t 11780 --&加油!在
==>;但我想通过Python运行相同的命令。在
prodataOSLib.executeCmd("pskill.exe -t 11780", True, True)
-->;工作愉快!在
现在我想把计算机名加入pskill突击队
prodataOSLib.executeCmd("pskill.exe \\localhost -t 11780", True, True)
-->;这不起作用
登录executeCmd函数会显示:
11-04-2011 13:35:15 [prodataoslib-executeCmd] - DEBUG: Executing command: C:\Users\JohanSA\Documents\EclipseWorkspace\ProdataATFBASE\src\resources\pskill.exe \localhost -t 11780
——>;问题是单词“localhost”前面只有一个反斜杠-->;但是“localhost”之前怎么能有这两个反斜杠呢?在
有人能帮我吗?在
非常感谢! 约翰
这是executeCmd函数:
def executeCmd (self,command, useResourceFolder=False, resultlogging=False):
''' Execute a command (default from current execution-folder) like you should type it in a DOS-prompt.
Parameters:
command = the command to be executed
useResourceFolder = False (=default) or True --> set True if you want to execute a file from the resourcefolder.
resultlogging = True when you want logging the result.
return: List with result-messages or error-messages
'''
if useResourceFolder:
command = os.path.abspath(os.path.join(self.currentdir, "..", "resources",command)) # Set path from resource directory
try:
self.logger.debug("Executing command: %s" % command)
output = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
resultfile = output.stdout
resultmessageList = []
for i in resultfile.readlines():
resultmessageList.append(i)
if resultlogging:
if len(resultmessageList) > 0:
resultstring=""
for messageline in resultmessageList:
resultstring = resultstring + messageline.replace('\n', '')
self.logger.debug("RESULT MESSAGE: %s " % resultstring)
return resultmessageList
except OSError, e:
self.logger.error("Execution FAILED. Exception: %s" %(e))
通过加前缀
r
,使字符串成为原始字符串。我无法理解代码和描述,但您要查找的是原始字符串,它是通过前缀r
获得的。像这样r'c:\localhost\nyprogram'
相关问题 更多 >
编程相关推荐