Writing Python Script from Batch Script is not working for one command

153 Views Asked by At

I'm trying to convert batch script into python script. This is batch script, which is calling Klockwork exe on the project specified building it.

%KwPath%\Kwinject -o kwinjectmp.out msbuild %BaseProjPath%/CodingGuide.vcxproj /t:Rebuild /p:Configuration="Release" /p:Platform="x64" /p:CLToolExe=cl.exe /p:CLToolPath=%VSBinPath% 

I have write equivalent python script for it.

args = KwPath + '\\Kwinject.exe sync -o ' + 'kwinjectmp.out' + 'msbuild ' + BaseProject + '\\' + ProjectFolder + '\\' + ProjectName + '/t:Rebuild /p:Configuration="Release" /p:Platform="x64" /p:CLToolExe=cl.exe /p:CLToolPath=' + VSBinPath
print(args)
subprocess.call(args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

Where I have declared BaseProject, VSBinPath, KwPath correctly. But the exectuion is not happening as it is happening in BatchScript, Basically script is not giving any output/working.

1

There are 1 best solutions below

0
Larcis On BEST ANSWER

spaces between arguments may be absent because of your usage. try this:

import os
path1 = os.path.join(KwPath, 'Kwinject.exe')
path2 = os.path.join(BaseProject, ProjectFolder, ProjectName)
subprocess.call([
        path1,
        'sync',
        '-o', 'kwinjectmp.out',
        'msbuild',
        path2,
        '/t:Rebuild',
        '/p:Configuration="Release"',
        '/p:Platform="x64"',
        '/p:CLToolExe=cl.exe',
        '/p:CLToolPath=' + VSBinPath
    ], 
    shell=True, 
    stdout=subprocess.PIPE, 
    stderr=subprocess.STDOUT
)