Link to home
Start Free TrialLog in
Avatar of techdoc6
techdoc6

asked on

PHP Exec Pipes

I'm trying to run a simple unix command via php, but php seems to be ignoring everything to the left of the pipe( | ).

In the example below, I'm trying to pipe the argument '/var' to the 'ls' command, which should give the output of the /var directory. Instead it gives the output of php's working directory, meaning that ls thinks there are no arguments coming in from the pipe.

Ultamitly, I want to get this running with a gpg command for encryption, but that should be pretty easy once I figure out why its not accepting pipes.
$command = 'echo /var | ls';
$return = shell_exec($command);
var_dump($return)
//returns the contents of php's working directory instead of the /var directory

Open in new window

Avatar of slyong
slyong

Can you try:

$command = 'ls /var';
??
Avatar of techdoc6

ASKER

Yea, that works fine. Its just when a pipe is introduced that problems arise. I've tried a few other test commands to see if the piping is working, and every time it seems as though the left side of the pipe is being ignored.
ASKER CERTIFIED SOLUTION
Avatar of slyong
slyong

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
sorry, that text file was my us50.txt