Jump to content
xisto Community
Sign in to follow this  
CrazyPensil

Running C Applications By Php (C - daemon)

Recommended Posts

I've faced up with a promlem. I've written a C-daemon(NOT C++ || C#) which needs to be run by a php-script on a UNIX-server. Can anybody explain me how to do this one using php's exec() or passthru() functions(I don't know unix)

Share this post


Link to post
Share on other sites

Hm, I'm sure someone will be able to help you out more, but I had to throw together a php form for my boss a few months back and it needed to pass data into a program and how I did it was simply to put

chdir ('../PROG LOCATION');echo exec('prog');

the chdir obviously was just to change it from the primary directory to where the c program was location, and then I used echo exec to call the program name... can't remember exactly "why" I used echo there, I assume it mattered haha. Sorry I can't be more help, I never really paid much attention when I did this except to get it working and don't have the time to look at it right now.

Share this post


Link to post
Share on other sites

Pretty much how Jeigh said. The echo is there because exec returns the output of the program as a string and you just wanted to print it out. Plain system() call does exactly the same. Passthru works the same way, it just directs the binary output of the program to the browser. You'll know when you have to use it. Since you mentioned that you are not familiar with unix... Remember to chmod the right permissions for your compiled program. You can do it with command "chmod a+x program". And as a side note, you can use these functions to run anything on the server. System commands, shell scripts, php scripts :(, ...

Share this post


Link to post
Share on other sites

Since you mentioned that you are not familiar with unix... Remember to chmod the right permissions for your compiled program. You can do it with command "chmod a+x program".

Thanks for your help... But.... Humm...
I've a little bit exaggerated with "a little of Unix knowledge"....
Coul you tell the correct chmod? :(

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.