Re: system, exec, shell_exec, passthru

From: Date: Mon, 14 Aug 2006 16:54:55 +0000
Subject: Re: system, exec, shell_exec, passthru
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-240640@lists.php.net to get a copy of this message
p.willis@telus.net wrote:
Hello, I am trying the run an external application with command line arguments using PHP under linux. ie: $command="myprog $arg1 $arg2 > textfile.txt"; system("echo \"$command\" > test.txt"); system($command); $handle=fopen("textfile.txt","r"); if($handle!=NULL) { while(!feof($handle)) { ... } fclose($handle); } I test my input arguments for the 'system' call by dumping the command into a text file. I can then test the command in the console. The commands work fine when run from the console. The commands don't work when run through the system command. I have tried system, exec, passthru, and shell_exec to no avail. Am I missing some permissions thing in my php.ini file? Thanks for any insight, Peter
Looking at your $command, there is no path in front of it. It's likely that PHP's shell doesn't have the program in its PATH. Try manually specifying the full path to the command: $command="/home/peter/myprog $arg1 $arg2 > textfile.txt"; (or whatever the path is) Keep in mind that under linux, (unlike DOS), you CANNOT execute applications in the same directory without a path. Even if the program is in the same directory as your present working directory (which is usually where the PHP script is located), you'd have to do "./myprog" as a relative path. Regards, Adam Zey.

« previous php.general (#240640) next »