Earth Patel
Earth Patel

Reputation: 21

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

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.

Upvotes: 0

Views: 161

Answers (1)

Larcis
Larcis

Reputation: 134

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
)

Upvotes: 1

Related Questions