Solved

Pass command directly to OS

Posted on 2006-11-28
7
722 Views
Last Modified: 2008-01-09
Hi...

I want to pass a command direct to the terminal.  In particular this command:

     cat /proc/cpuinfo | grep 'model name' | sed -e 's/.*: //'

and then have it displayed nice and neatly on the page.  

Currently my code looks like this:
    $cmd = "cat /proc/cpuinfo | grep 'model name' | sed -e 's/.*: //' ";
    shell_exec($cmd);

But instead of running I get an error telling me:
    Warning: shell_exec() [function.shell-exec]: Cannot execute using backquotes in Safe Mode in /var/www/web3/web/network.php on line 4

Does anyone know a way for me to get command to run? I've also tried to echo exec() and popen(), but exec gave me no errors and no output... whilst popen gave me the cryptic output "Resource id #2".

Thanks in advance.
0
Comment
Question by:Mr_Lenehan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 29

Expert Comment

by:TeRReF
ID: 18030491
PHP runs in safe_mode. This means that there's only 1 dir that's enabled to run programs from.
Look for that dir with this command:
phpinfo();

(put it in a seperate file and run it...)
0
 
LVL 2

Author Comment

by:Mr_Lenehan
ID: 18030548
Ran phpinfo and found the following:

Directive                       Local             Master
safe_mode                   On                     Off
safe_mode_exec_dir      no value      no value

I take it the safe mode options are configured in php.ini?
0
 
LVL 29

Accepted Solution

by:
TeRReF earned 500 total points
ID: 18030560
Yes, that's right.
The directives are already there, find them and uncomment/ define them...
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 2

Author Comment

by:Mr_Lenehan
ID: 18030567
Okay, answered that bit myself. How do I restart php on unix?
0
 
LVL 29

Expert Comment

by:TeRReF
ID: 18030695
You restart Apache, become root and type this command:
apachectl stop && apachectl start
0
 
LVL 2

Author Comment

by:Mr_Lenehan
ID: 18030710
cheers
0
 
LVL 29

Expert Comment

by:TeRReF
ID: 18030716
You're welcome :)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question