Accessing An External Programm

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
neel_basu
Forum Contributor
Posts: 454
Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India

Post by neel_basu »

Actually
I am now A 18 Years Old Boy
And I Have Learned JavaScript, php, MySQL,AJAX All By MyShelf In Somany Difficulties
Only By Reading Books.Nobody Except MyShelf And Mu Computer Helped Me .

After That I Have Decided To Create My Own Website That Will Provide
Community , Chatting ,And a Service LIke Ask.com
And My Own Messenger,And A Mail Sender Desktop Applicetion

And For Security Measures Of My Site I Thought That There Will be My Own Encryption Module

And It Was My Dream

And Now I Have Got So Many Thousands Of Teachers And Friends To Consult To Know A Bit More For Help

So I Must Make My Dream Successful Now.
:D
Thanks A Lot
User avatar
neel_basu
Forum Contributor
Posts: 454
Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India

Post by neel_basu »

Well
If I Build This C File Under Linux And Build pass_arg.out With This Code

Code: Select all

#include <stdio.h> 

int main(int argc,char *argv[]) 
{ 
        int x; 

        printf("%d\n",argc); 
        for(x=0;x<argc;x++) 
                printf("%s\n",argv[x]); 
    return 0; 
}
After That Access That pass_arg.out With This Code Would It Work ??

Code: Select all

$output =  shell_exe('pass_arg.out arg1 arg2'); 
echo $output;
Would Then This php File Work To Pass An Arg and To Get The Output ??
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post by dibyendrah »

Sure neel_basu ! It will work. shell_exec function executes and returns the output to $output variable.

just like if you do

Code: Select all

$out = shell_exec("ls -la");
print $out;
It will execute the ls program with command line argument -la and returns the result to $out.
User avatar
neel_basu
Forum Contributor
Posts: 454
Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India

Post by neel_basu »

Thanks a Lot
User avatar
neel_basu
Forum Contributor
Posts: 454
Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India

Post by neel_basu »

But The File ls Here Doesnt have an Extension
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Doesn't matter.
User avatar
neel_basu
Forum Contributor
Posts: 454
Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India

Post by neel_basu »

Can This Code Run On Linux ?
Well
If I Build This C File Under Linux And Build pass_arg.out With This Code C:
#include <stdio.h>

int main(int argc,char *argv[])
{
int x;

printf("%d\n",argc);
for(x=0;x<argc;x++)
printf("%s\n",argv[x]);
return 0;
}



After That Access That pass_arg.out With This Code Would It Work ??
php:
$output = shell_exe('pass_arg.out arg1 arg2');
echo $output;
Would Then This php File Work To Pass An Arg and To Get The Output In Linux ??
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Post by ok »

I think that it will work.

The best way to know if something works is to test it.
User avatar
neel_basu
Forum Contributor
Posts: 454
Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India

Post by neel_basu »

I am A Windows User I will Shift To Linux On The Day Night
I Wanna Know Which Linux Suits Best For Me ??
Still Now I Dont Know anything Of Linux
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Post by ok »

I tested it and it can run but the PHP code should like that:

Code: Select all

$output = shell_exec('/full/path/to/executable/pass_arg.out arg1 arg2');
echo $output;
BTW, the output is:
3 /full/path/to/executable/pass_arg.out arg1 arg2
Which means that the first argument in the argv array is the filename.
User avatar
neel_basu
Forum Contributor
Posts: 454
Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India

Post by neel_basu »

If I Use A Shared Hosting

I Uploaded That binary File To The Same Folder In Which The php Script Is
Does The full Path Is Also Needed then ??

If I Use A Shared Hosting How Can I Give The Full Path
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Post by ok »

Try through PHP to get the full path. I think:

Code: Select all

echo $_SERVER['PATH_TRANSLATED'];
User avatar
neel_basu
Forum Contributor
Posts: 454
Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India

Post by neel_basu »

I Mean In Shared Hosting I Have public_html Folder Under My Domain.
Suppose I Have Kept My pass_arg.out File There Then What Will Be The Code ??
Would You Please Give Me The Compleate Code ??
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post by dibyendrah »

neel_basu wrote:If I Use A Shared Hosting

I Uploaded That binary File To The Same Folder In Which The php Script Is
Does The full Path Is Also Needed then ??

If I Use A Shared Hosting How Can I Give The Full Path
I think shared host will not allow to use shell_exec, exec and other functions for executing binaries because most of the shared are either deploying the php in safe mode or they just don't allow to use different functions.
User avatar
neel_basu
Forum Contributor
Posts: 454
Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India

Post by neel_basu »

No There Are Only A Few Hosts Where php Runs In Safe Mode
Post Reply