Calling Msbuild from Php - Wrong Codepage and Culture
I have a Php script that calls Msbuild via System:
<?php
system( "msbuild umlaut.proj" );
?>
This is the project file:
<?xml version="1.0" encoding="UTF-8"?>
<Project
xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
DefaultTargets="EchoUmlaut"
ToolsVersion="3.5">
<Target Name="EchoUmlaut">
<Message Text="Umlaute: Ä Ö Ü ä ö ü ß" />
</Target>
</Project>
When I call Msbuild directly from the command line the output of msbuild is in German (as excpected) and the umlauts come out OK (I chcp to 1252). But when I use php to call msbuild the umlauts are wrong, and the output of msbuild is changed to English. I wonder what I can do to prevent this.
C:\>chcp
Aktive Codepage: 1252.
C:\>msbuild umlaut.proj
Microsoft (R)-Buildmodul, Version 3.5.30729.1
[Microsoft .NET Framework, Version 2.0.50727.3607]
Copyright (C) Microsoft Corporation 2007. Alle Rechte vorbehalten.
Das Erstellen wurde am 13.04.2010 08:57:04 gestartet.
Projekt "D:\Cvsroot\projekte\e4elaui\v1.0\umlaut.proj" auf Knoten 0 (Standardziele).
Umlaute: Ä Ö Ü ä ö ü ß
Die Erstellung von Projekt "D:\Cvsroot\projekte\e4elaui\v1.0\umlaut.proj" ist abgeschlossen (Standardziele).
Das Erstellen war erfolgreich.
0 Warnung(en)
0 Fehler
Vergangene Zeit 00:00:00
C:\>php call_from_php.php
Microsoft (R) Build Engine Version 3.5.30729.1
[Microsoft .NET Fr开发者_运维知识库amework, Version 2.0.50727.3607]
Copyright (C) Microsoft Corporation 2007. All rights reserved.
Build started 13.04.2010 08:57:11.
Project "D:\Cvsroot\projekte\e4elaui\v1.0\umlaut.proj" on node 0 (default targets).
Umlaute: Ž ™ š „ ” á
Done Building Project "D:\Cvsroot\projekte\e4elaui\v1.0\umlaut.proj" (default targets).
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:00
Looks like the php script is not passing in some of the environment variables that the shell passes in. You will need to set them manually using putenv:
bool putenv ( string $setting );
copy them from the shell and paste them into the script before calling system.
精彩评论