0

概括:

我想在 python 中执行一个 pskill.exe 命令。在 dos-prompt 中尝试过:C:\Users\JohanSA\Documents\EclipseWorkspace\ProdataATFBASE\src\resources\pskill.exe \localhost -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] - 调试:执行命令:C:\Users\JohanSA\Documents\EclipseWorkspace\ProdataATFBASE\src\resources\pskill.exe \localhost -t 11780

--> 问题是“localhost”这个词之前只有1个反斜杠-->但是我怎么能在“localhost”之前有这2个反斜杠呢?

谁能帮我这个?

非常感谢!约翰

这是 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))
4

1 回答 1

1

通过前缀将您的字符串作为原始字符串r。我无法理解代码和描述,但是您要查找的内容称为 raw_string ,它是通过前缀获得的r。像这样r'c:\localhost\nyprogram'

于 2011-04-11T11:59:51.447 回答