def Expand(pArgs, pFilePath, pSearchPath, pSection, pSep='!!', pList=False, pVerbose=False):
    '''
    Extract command from file and replace all macros
    pArgs        -- Args passed to program except file path and section name
    pFilePath    -- File to use in macro expansion
    pSearchPath  -- File to scan for command '
    pCount       -- Number of lines at the start of the file to scan
    pSep         -- String used to identify end of command
    pHelp        -- True to display available commands
    '''
#   ---- Find command    
    lCommand = FindCommand(pArgs[0], pFilePath,  pSearchPath, pSection, pList=pList, pVerbose=pVerbose)
    
#   ---- Expand and insert/append any passed arguments       
#        Arguments on original pb.py command line will replace {} from left to right
#        otherwise they will be appended to the end of the command 
    lStart = 1
    if len(lCommand) > 0:
        if len(pArgs) > lStart:
            for lArg in pArgs[lStart:]:
                if lArg.find('{') >= 0:
                    lArg = Do2.ExpandArg(lArg, pFilePath, '')
                if len(lArg) > 0:
                    try:
                        lTest = os.path.abspath(lArg)
                        if os.path.exists(lTest):
                            if lTest.find(" ") > 0:
                                lTest = '"' + lTest + '"'
                            lArg = lTest
                    except:
                        pass
                lPos = lCommand.find('{}')
                if lPos >= 0:
                    lCommand = lCommand[0:lPos] + lArg + lCommand[lPos+2:]
                else:
                    lCommand += ' ' + lArg
    
#   ---- Prevent unwanted arguments appended to command                    
    lPos = lCommand.rfind(pSep)
    if lPos > 0:
        lCommand = lCommand[0:lPos]
    
#   ---- Expand all remaining macros
    if lCommand.find('{') >= 0:
        lCommand = Do.Expand(lCommand, pFilePath)
        
    return lCommand

    Extract command from file and replace all macros
    pArgs        -- Args passed to program except file path and section name
    pFilePath    -- File to use in macro expansion
    pSearchPath  -- File to scan for command '
    pCount       -- Number of lines at the start of the file to scan
    pSep         -- String used to identify end of command
    pHelp        -- True to display available commands
    
recipes/Python/577453_Extract_expexecute_commQEditor_menu_file_file/recipe-577453.py