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

how to use exec()

P: 3
Hi
I want to execute a command on the cmd prompt thru php..

Exp: I want to execute 'ls' and store the list in a file.
I tried using exec() function but it returns 1..
not able to see the list.

how to go about it?
Jun 13 '06 #1
Share this Question
Share on Google+
4 Replies


Banfa
Expert Mod 5K+
P: 8,916
I imagine that as a security precaution this may have been disabled.
Jun 13 '06 #2

P: 5
Try

"which php"

If it doesn't find it, then look in /usr/local/bin/ or /usr/bin

If you're on windows, gotta find the directory for PHP and add it to your PATH env varible.

Other wise, you just do

php -f thing.php

and thing.php is

#!/usr/local/bin/php
<?php
system("ls -l");
?>

What platform are you on?
Jun 16 '06 #3

P: 3
I am working on windows platform..
I am using WAMP.


I want to execute a command on command prompt and redirect its output to a File..
How to go about it??
Jun 19 '06 #4

sashi
Expert 100+
P: 1,754
Hi Gauri,

first off all check the system environment variable for the PHP path.. since ur working of WAMP the environment variable should have been created by default provided u have installed .msi version.. btw which version of WAMP did you install??

another shortcut to find the PATH is.. goto ur command prompt n type the command PATH.. see what you get n make sure the PHP path is listed there as well..

then to execute as command.. lets assume.. save the below as notepad.php

<?php
passthru("c:\windows\system32\notepad.exe");
?>

then from the cmd prompt.. type..

c:\path-to-php\php.exe c:\path-to-the-notepad.php

tips of the day..

the shell_exec() command can also be used.. this command is more suitable when it comes to executing shell command.. :)

good luck..
Jun 19 '06 #5

Post your reply

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