1

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)
subprocess.check_call(command)
print(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.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Jul 18, 2017 at 14:22

1 Answer 1

2

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.

answered Jul 18, 2017 at 15:29
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.