Search code examples
python-3.xfilecmdfilelist

how to compile file list through shell by python


i am new in python. i have to create a list with file name with its path and some commands in python. which i have to execute in cmd. it will open compiler and the set some settings in it for compiling the files. my problem is, when i type manully couple of files with commands in cmd at that time it will work but when i execute same list through python it says it can not find the pinmap file. the following lines i write in cmd and it works fine. (apc and start with '-' are command of cmd) apc G:\Organisation\TE\Patel\ASCII_Open_Program\src\atp\Functionality\clk_Watchdog.atp G:\Organisation\TE\Patel\ASCII_Open_Program\src\atp\Functionality\CP_UV_Threshold.atp -opcode_mode single -pinmap_workbook G:\Organisation\TE\Patel\ASCII_Open_Program\src\xls\PinMap_BE.txt -comments

i think i am doing same thing in python. my code is

def APC_Compiler():
    list = ["apc "]
    #list.append('apc ')
    for root,dirs,files in os.walk(atp_folder_path + '\\SCAN'):
        for file in files:
            if file.endswith(".atp"):                  
                 list.append(os.path.join(root, file))

    list.append(' -opcode_mode single ')
    list.append(' -pinmap_workbook  ')
    list.append(' G:\\Organisation\\TE\\Patel\\ASCII_Open_Program\\src\\xls\\PinMap_BE.txt')
    list.append(' -comments ')              
    print (list)
    subprocess.call(list)  

can anyone please tell me what am i doing wrong. is there any better way to make the list of files with commands and executing it??


Solution

  • here is my solution, all i have to do, is to add one instruction which can convert all the list in to one single string and execute it. I have commented the near to the instruction, which i have added to solve my problem.

    def apc_compiler():
            """ Compiles all the *.atp files into *.pat file """
    
        list = ['apc ']
        for root, dirs, files in os.walk(atp_folder_path):
            for file in files:
                if file.endswith('.atp'):
                    list.append(os.path.join(root, file) + ' ')
    
        list.append(' -opcode_mode single ')
        list.append(' -pinmap_workbook ')
        list.append(pinmap_folder_path)
        list.append(' -comments ')
        list = ''.join(list) # instruction to convert list in to single string
    
        subprocess.call(list)