2

I have a python script that is doing some deployment. I want to run that script from msbuild and get the output in case it pass, or failed. So, how can I communicate to msbuild of the status , and the error text? I want to show the result on the build server. I have to use python 2.7, and cannot use 3.x

Ghassan Karwchan
  • 3,355
  • 7
  • 37
  • 65

1 Answers1

6

Run the command using the Exec task and capture it's output. For example:

<Target Name="GetPythonOutput">

  <PropertyGroup>
    <PyCommand>/path/to/python.exe -a /path/to/pthonfile</PyCommand>
    <TempFile>ExecTempFile</TempFile>
  </PropertyGroup>

  <Exec Command="$(PyCommand) &gt; $(TempFile)" />

  <ReadLinesFromFile File="$(TempFile)">
    <Output TaskParameter="Lines" ItemName="PyOutput"/>
  </ReadLinesFromFile>
  <Delete Files="$(TempFile)" />

  <Message Text="Python command output was: @(PyOutput)" />
</Target>

If you are using .Net 4.5 things are better since Exec can do most of the work for you

Community
  • 1
  • 1
stijn
  • 34,664
  • 13
  • 111
  • 163