The ProgrammersTalk Community
Forum Register Search Today's Posts Mark Forums Read
Register

Go Back   The ProgrammersTalk Community > Web Programming > PHP


Welcome to the The ProgrammersTalk Community forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.
Tags: ,

Closed Thread
 
LinkBack Thread Tools    Display Modes   
  #1 (permalink)  
Old 06-25-2008, 05:59 AM
sarel sarel is offline
Novice
Join Date: Jun 2008
Posts: 11
iTrader: (0)
sarel is on a distinguished road
[SOLVED] Shell execution

I need some help with executing a shell using PHP.

The shell is in the following path:

c:\tools\bin\ogr.exe

I have read that <?php $cmd = command string ; shell_exec($cmd); ?> will di the trick but how do I get this function to execute the shell in the above path??


Sarel

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
  #2 (permalink)  
Old 06-25-2008, 06:20 AM
Lee's Avatar
Lee Lee is offline
PT Staff*
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: Blackpool, UK
Posts: 616
iTrader: (0)
Lee will become famous soon enoughLee will become famous soon enoughLee will become famous soon enoughLee will become famous soon enough
Quote:
Originally Posted by sarel View Post
I need some help with executing a shell using PHP.
c:\tools\bin\ogr.exe

<?php $cmd = command string ; shell_exec($cmd); ?>

I have not done this before but wouldn't the command string be the path?

So:
PHP Code:
<?php
$cmd 
"c:\tools\bin\ogr.exe";
shell_exec($cmd); 
?>

Last edited by Lee : 06-25-2008 at 09:19 AM.
The Following User Says Thank You to Lee For This Useful Post:
sarel (06-27-2008)
  #3 (permalink)  
Old 06-25-2008, 06:43 AM
sarel sarel is offline
Novice
Join Date: Jun 2008
Posts: 11
iTrader: (0)
sarel is on a distinguished road
Correct, I just got it, so your command string includes:

path and then the actual command


__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
  #4 (permalink)  
Old 06-25-2008, 09:19 AM
Lee's Avatar
Lee Lee is offline
PT Staff*
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: Blackpool, UK
Posts: 616
iTrader: (0)
Lee will become famous soon enoughLee will become famous soon enoughLee will become famous soon enoughLee will become famous soon enough
Good to here you got it going then, maybe you could post up how you did it so someone reading this thread in the future knows
  #5 (permalink)  
Old 06-26-2008, 06:43 AM
sarel sarel is offline
Novice
Join Date: Jun 2008
Posts: 11
iTrader: (0)
sarel is on a distinguished road
Icon13

Ok the shell exec was relative easy, I have a problem with placing in variables so that the shell commands can be dynamic or user driven.

such as the following:

Code:
<?php 
$output = shell_exec('C:/FWTools2.2.1/bin/ogr2ogr -f "$filetype" c:/mygisdata/$postgislayer.$file_ext PG:"host=localhost user=postgres dbname=mdssdata password=database" "$postgislayer" ');

 echo "<pre>$output</pre>";
?>
the Problem:

the echo doesn't seem to "echo" the the variables in the $output string.

I think it might be the way I use quotes around the variables, the quotes are required on the shell command.

Hope someone can help.

Thanks
Sarel

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!

Last edited by sarel : 06-26-2008 at 06:45 AM.
  #6 (permalink)  
Old 06-26-2008, 07:56 AM
MrPickle's Avatar
MrPickle MrPickle is offline
Sr. Programmer
Join Date: Nov 2007
Location: England, Lincolnshire
Posts: 279
iTrader: (0)
MrPickle is on a distinguished roadMrPickle is on a distinguished roadMrPickle is on a distinguished road
You need to put . before and after like so:

Code:
echo "<pre>" . $output . "</pre>";

__________________
PM me and tell me your name or a phrase and I shall write it in Elf for you. English Tengwar to be precise.
Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
The Following User Says Thank You to MrPickle For This Useful Post:
sarel (06-27-2008)
  #7 (permalink)  
Old 06-27-2008, 01:10 AM
sarel sarel is offline
Novice
Join Date: Jun 2008
Posts: 11
iTrader: (0)
sarel is on a distinguished road
Icon5


No sorry that didn't work

but no worries I got it working, it was those devilish quotes as expected.

so double quotes are required for the shell command and to get them attached on the variables when echo-ing is done by doing so:

\"$variable\"

so place the entire string into $cmd
then
echo the shell+$cmd like so:

echo "<pre>".shell_exec($cmd)."</pre>";

yahooooooooooooooooooooooo aaaaaaaaaaaaggghhhh

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Closed Thread


Thread Tools
Display Modes

   Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -7. The time now is 11:34 AM. Powered by vBulletin
Copyright © 2000 - 2007, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO © 2007 ProgrammersTalk Sedo - Buy and Sell Domain Names and Websites project info: programmerstalk.net Statistics for project programmerstalk.net etracker® web controlling instead of log file analysis


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50