By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,982 Members | 1,919 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,982 IT Pros & Developers. It's quick & easy.

how to get value from php to shell command

P: 43
this is my code:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $name = POST_["grib_name"];
  3.  
  4. $output2 = shell_exec('Gribinfo  $shell_name' );
  5. echo "<pre>$output2</pre>";
  6. ?>
  7.  
here , I wanna the $shell_name, which is in shell command, get the value of $name which is in php.
Anyone knows how to do it ???
Thanks a million !
Tanya
May 21 '07 #1
Share this Question
Share on Google+
5 Replies


Motoma
Expert 2.5K+
P: 3,235
this is my code:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $name = POST_["grib_name"];
  3.  
  4. $output2 = shell_exec('Gribinfo  $shell_name' );
  5. echo "<pre>$output2</pre>";
  6. ?>
  7.  
here , I wanna the $shell_name, which is in shell command, get the value of $name which is in php.
Anyone knows how to do it ???
Thanks a million !
Tanya

Two ways to do it: use double quotes ($output2 = shell_exec("Gribinfo $name");) or string concatenation ($output2 = shell_exec('Gribinfo '.$name);)
May 21 '07 #2

P: 43
Two ways to do it: use double quotes ($output2 = shell_exec("Gribinfo $name");) or string concatenation ($output2 = shell_exec('Gribinfo '.$name);)
Thanks for answering,
I tried both, but neither works.

when I use
$output2 = shell_exec('Gribinfo $name');
the result means no value of $name passed in.

when I use
$output2 = shell_exec("Gribinfo $name"); and
$output2 = shell_exec('Gribinfo '.$name);
nothing come out.
May 22 '07 #3

Motoma
Expert 2.5K+
P: 3,235
This line is wrong.
Expand|Select|Wrap|Line Numbers
  1. $name = POST_["grib_name"];
  2.  
It should be this.
Expand|Select|Wrap|Line Numbers
  1. $name = $_POST['grib_name'];
  2.  
May 22 '07 #4

P: 43
This line is wrong.
Expand|Select|Wrap|Line Numbers
  1. $name = POST_["grib_name"];
  2.  
It should be this.
Expand|Select|Wrap|Line Numbers
  1. $name = $_POST['grib_name'];
  2.  

I wrote it right before , it was $_POST["grib_name"];

and nothing wrong with your two ways,
the problem is :
Each time you call shell_exec, it operates in a completely new shell.
I added this :
chdir("/home/.../grib_downloaded");
to specify the directory again. it works !
thanks for your help !
Tanya
May 22 '07 #5

Motoma
Expert 2.5K+
P: 3,235
I wrote it right before , it was $_POST["grib_name"];

and nothing wrong with your two ways,
the problem is :
Each time you call shell_exec, it operates in a completely new shell.
I added this :
chdir("/home/.../grib_downloaded");
to specify the directory again. it works !
thanks for your help !
Tanya
Glad everything worked out well. Come back any time you have a problem.
May 22 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.