See More
Popular Forum

MBA (4887) B.Tech (1769) Engineering (1486) Class 12 (1030) Study Abroad (1004) Computer Science and Engineering (988) Business Management Studies (865) BBA (846) Diploma (746) CAT (651) B.Com (648) B.Sc (643) JEE Mains (618) Mechanical Engineering (574) Exam (525) India (462) Career (452) All Time Q&A (439) Mass Communication (427) BCA (417) Science (384) Computers & IT (Non-Engg) (383) Medicine & Health Sciences (381) Hotel Management (373) Civil Engineering (353) MCA (349) Tuteehub Top Questions (348) Distance (340) Colleges in India (334)
See More

Calling Python ogr2ogr from PHP doesn't work as expected?

General Tech Bugs & Fixes

Max. 2000 characters



( 5 months ago )


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\\ $without_extension");
echo $tmp1;
echo "<br>";
$tmp2 = exec("C:\\ms4w\\Python\\python C:\\ms4w\\Apache\\cgi-bin\\ $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.



( 5 months ago )

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.

what's your interest