[PLUG-TALK] php system command problem

wes plug at the-wes.com
Mon May 26 11:51:14 PDT 2008


When I'm troubleshooting this sort of thing, I have found that it is usually
some kind of environment issue causing trouble.

First, have you tried allowing output? It might give a clue. "$command =
"/home/rsteff/bin/x10 turn k5 on";

Next, try running the command in a subshell. The simpler, the better.
Something like "sh /home/rsteff/bin/x10 turn k5 on".

If that succeeds and looks normal, try running "sh env" from a shell, and
"system(env)" from php. See if they're different, and if any of the
differences look helpful.

Another thing to check is what user php runs as. You could run
"system(whoami)" as a start for figuring that out. If it's a user other than
rsteff, you may be having a permissions issue.

As a last resort, you can run strace/ktrace or something similar in both
places.

shell: "strace /home/rsteff/bin/x10 turn k5 on > strace_output_shell 2>&1"
php: "system(strace /home/rsteff/bin/x10 turn k5 on > strace_output_php
2>&1"

And then see if there's anything odd in the resulting different files.

If you don't have strace, you should install it. :)

-wes

On Mon, May 26, 2008 at 11:23 AM, Richard C. Steffens <rsteff at comcast.net>
wrote:

> Some years ago I wrote a php program to play music from my collection of
> .mp3 files on the living room stereo using a machine in the basement.
> Before the machine died, the program worked, so I know that what I used
> to do with that version of php worked. While I can't be certain, I think
> I was using php 4.
>
> Today I'm trying to write a php program to control my x10 CP-290. I'm
> using the php system command to send commands to a program called x10.
> If I run the x10 program from the command line it does what it's
> supposed to do. When I run it from the system command of php 5, nothing
> happens.
>
> I've tried simple things like sending "ls -a" from the system command in
> php and I get what I expect.
>
> The x10 command that works from the command line looks like this:
>
> rsteff at Moonguide:~> x10 turn k5 on > /dev/null &
> [1] 23509
> rsteff at Moonguide:~>
> [1]+  Done                    x10 turn k5 on >/dev/null
> rsteff at Moonguide:~>
>
> The way I'm trying to use it in php looks like this:
>
>        <?php
>
>          // Build command string
>          $command = "/home/rsteff/bin/x10 turn k5 on > /dev/null &";
>
>          // Send command
>          system($command);
>
>          ?>
>
> I'm guessing that there's some subtle thing I'm missing. Application of
> appropriate clue stick requested.
>
>
> --
> Regards,
>
> Dick Steffens
>
> _______________________________________________
> PLUG-talk mailing list
> PLUG-talk at lists.pdxlinux.org
> http://lists.pdxlinux.org/mailman/listinfo/plug-talk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pdxlinux.org/pipermail/plug-talk/attachments/20080526/6a5d01f2/attachment.html>


More information about the PLUG-talk mailing list