I have a HTML page that takes and uploaded zip file and then calls a PHP page as a form action. That PHP then calls two Python scripts in my Apache cgi-bin. The first Python script runs with no issue and simply unzips the uploaded file within a sub directory. The second Python script includes a subprocess call to a command line tool to perform some action on the unzipped files. However, I am finding that using the exec() in PHP for the second Python script with the subprocess does not work. If I run the Python script from the command line it works fine. But, if I call it from the PHP exec function it does nothing.

The snippet of PHP:

$tmp1 = exec("C:\\ms4w\\Python\\python C:\\ms4w\\Apache\\cgi-bin\\unzip_shp.py $without_extension");
echo $tmp1;
echo "<br>";
$tmp2 = exec("C:\\ms4w\\Python\\python C:\\ms4w\\Apache\\cgi-bin\\convert_to_geojson.py $without_extension", $output);
echo $output

The snippet of Python:

command = "C:\\ms4w\\tools\\gdal-ogr\\ogr2ogr.exe -f \"GeoJSON\" "+sys.argv[1]+".geojson "+sys.argv[1]+".shp" #os.system(command)

The print command in the Python returns this to the PHP:

C:\ms4w\tools\gdal-ogr\ogr2ogr.exe -f "GeoJSON" C:\ms4w\Apache\htdocs\uploads\parks_escambia.geojson C:\ms4w\Apache\htdocs\uploads\parks_escambia.shp

Also, I am running this all on a Windows OS as a localhost development server. Using Python version 2.7.

1 Answer 1


You may need to set some of GDAL's environmental variables when you run subprocess, such as GDAL_DATA.

You can see which are being set in the MS4W setenv.bat script.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.