Command line funciton
Moderator: General Moderators
Command line funciton
Is there a function in php that allows me to execute a command on the command-line or shell? I remember coming across one but don't remember what the name of it was. I checked on php.net and couldn't find it. Eeek.
Is there such a thing or am I mistaken?
Is there such a thing or am I mistaken?
Re: Command line funciton
Awesome! Thanks.
But what's the difference between shell_exec() and exec() and even system() for that matter?
EDIT: also I can't seem to get and error if something goes wrong.
But what's the difference between shell_exec() and exec() and even system() for that matter?
EDIT: also I can't seem to get and error if something goes wrong.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Command line funciton
The manual explains the differences between the various functions:
http://us.php.net/manual/en/ref.exec.php
http://us.php.net/manual/en/ref.exec.php
(#10850)
Re: Command line funciton
Hmm, I can't seem to execute this:
I get the status code 127.
Code: Select all
$output = exec("flvmdi", $output, $status);
print_r(str_replace("\n", "<br/>", $output)."<br/><br/>".$status);
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Command line funciton
What OS? Can the webserver user execute that command (permission and in path)?
(#10850)
Re: Command line funciton
Well I know that exec("ls") works and in the php info safe_mode is off. So exec() works.
I think my server is linux, I'm not sure which version of linux. It's a godaddy shared server, if your familiar with them.
I think my server is linux, I'm not sure which version of linux. It's a godaddy shared server, if your familiar with them.
Re: Command line funciton
Use full path to the executable file.
There are 10 types of people in this world, those who understand binary and those who don't
Re: Command line funciton
I'm actually doing that too. And the same thing happens. What is 127 status mean? Why aren't I getting an error of any kind?
Re: Command line funciton
As arborint suggested, post the output of
Also, to see what really happens use passthru() instead of exec() and add 2>&1 at the end of the command string.
Code: Select all
ls -l full/path/commandThere are 10 types of people in this world, those who understand binary and those who don't
Re: Command line funciton
The output of the ls command:
BTW: I'm a complete noob to linux and command lines so please bare with me.
EDIT: also I tried:
and got:
I changed the username and /path/to/ part. The 0 is the status code.-rw-r--r-- 1 username inetuser 242688 Jul 19 23:35 /path/to/flvmdi.exe
0
BTW: I'm a complete noob to linux and command lines so please bare with me.
EDIT: also I tried:
Code: Select all
$output = passthru("/path/to/flvmdi.exe 2>&1", $status);
print_r(str_replace("\n", "<br/>", $output)."<br/><br/>".$status);
sh: line 1: /home/content/t/r/a/tradingtresure/html/manager/chart-room/flvmdi.exe: Permission denied
126
Re: Command line funciton
Code: Select all
chmod 0755 /path/to/flvmdi.exeThere are 10 types of people in this world, those who understand binary and those who don't
Re: Command line funciton
I found out the hard way that shared servers don't usually like executing commands, likely for a good reason.
(I originally had written a script that used a command to delete a directory "rm -r directory", and had to replace it with a recursive PHP function)
If I may ask, what are you trying to do from the command line? It may be a good idea to instead find a way to do it using just PHP, it will certainly help with compatibility issues.
-OmniUni
(I originally had written a script that used a command to delete a directory "rm -r directory", and had to replace it with a recursive PHP function)
If I may ask, what are you trying to do from the command line? It may be a good idea to instead find a way to do it using just PHP, it will certainly help with compatibility issues.
-OmniUni
Re: Command line funciton
I'm trying to run a program called FLVMDI (FLV MetaData Injector) that will inject metadata information into my flv videos. I've trying searching the net for a php metadata injector but haven't found any. I was thinking of building one myself but I don't really know how that kind of data is injected/written in flvs.
Re: Command line funciton
This is a windows program and will not work under your Linux server, unless you configure it with WINE somehow.
I'm sorry,
-OmniUni
I'm sorry,
-OmniUni