0

I created a simple C program that takes an integer argument and outputs that integer plus two. I can run it in a terminal with

./simplep 2

and in PHP with

exec('./simplep 2', $output).

I have a more complicated program called myprogram which involves an external library. I can run it in the terminal with

./myprogram a.mov

but it fails if I run it in PHP with

exec('./myprogram a.mov', $output)

No output is produced, which makes me think the program isn't running at all.

PS. I am working on Mac.

update

From the error ouput I know the problem is the library. It says

dyld: Library not loaded: /opt/local/lib/libjpeg.8.dylib". 

But the library file is there.

7
  • 1
    What does the error message say? If there is no error message, make sure PHP error reporting is enabled. If there still isn't any error message then it sounds like your program is failing... is it reporting errors correctly? Commented Jun 25, 2012 at 18:28
  • What OS is this? I assumed a UNIX operating system because of the forward slashes. Commented Jun 25, 2012 at 18:31
  • Windows can stop gui apps from opening, see comment at bottom: php.net/manual/en/book.exec.php Commented Jun 25, 2012 at 18:34
  • @cdhowie I enabled the error reporting, and there is no error reported. Commented Jun 25, 2012 at 18:36
  • @notfed It says "cannot execute binary file". I tried chmod +x but still get this error. Commented Jun 25, 2012 at 18:48

3 Answers 3

2

It's probably producing an error, but it's going to stderr instead of stdout. One simple way to view stderr here is to change:

exec('./myprogram a.mov', $output)

to

exec('./myprogram a.mov 2>err.out', $output)

and view the file err.out to see what the error message is.

EDIT:

Now that you posted the error, it looks like a dynamic library is not being loaded. The most likely reason is that environment variables are not being passed to exec, and the DYLD_LIBRARY_PATH environment variable is being cleared out. See what DYLD_LIBRARY_PATH is on your terminal (via env), then try running:

exec('env DYLD_LIBRARY_PATH=XYZ ./myprogram a.mov 2>err.out', $output)

Where XYZ is the value of DYLD_LIBRARY_PATH on your terminal.

Sign up to request clarification or add additional context in comments.

Comments

1

Do you have right permissions to run myprogram with exec? Try this

chmod +x myprogram

1 Comment

That's odd. Can you see if there are any logs doing cd /var/log; grep -R -n myprogram ./*
0

If your program runs on command line, try using shell_exec instead of exec.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.