write command line code in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zzclare
Forum Newbie
Posts: 11
Joined: Wed Nov 10, 2010 5:22 am

write command line code in php

Post by zzclare »

Hello,

I have windows and apache server installed in my computer. I want to execute command line code with php.
for instance, if I type this code in command line window shp2qgsql buildings.shp > bui.sql
it will convert shape file to sql table in certain file directory.Now I want to develope an application that do it automatically. It means I want to execute this code in php so whenever my webpage run it, it will generate a sql table. I found a exec() might be right function. My code look like this:

<?php
$result ="shp2pgsql buildings.shp > bui.sql";
exec('/usr/bin/top -b -n1, $result');
?>


but I didn´t get the sql table in the directory. Can anyone help me?

Many Thanks
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: write command line code in php

Post by Celauran »

I'm not sure exactly how exec() behaves in a Windows environment, but that code won't ever do what you want since you're calling top, which doesn't exist in Windows. Maybe try exec($result)?
Post Reply