Page 4 of 5
Posted: Thu Dec 07, 2006 9:22 am
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.
Thanks A Lot
Posted: Thu Dec 07, 2006 9:55 am
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 ??
Posted: Thu Dec 07, 2006 11:05 am
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.
Posted: Thu Dec 07, 2006 11:08 am
by neel_basu
Thanks a Lot
Posted: Thu Dec 07, 2006 12:35 pm
by neel_basu
But The File ls Here Doesnt have an Extension
Posted: Thu Dec 07, 2006 12:41 pm
by volka
Doesn't matter.
Posted: Thu Dec 07, 2006 12:44 pm
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 ??
Posted: Thu Dec 07, 2006 12:47 pm
by ok
I think that it will work.
The best way to know if something works is to test it.
Posted: Thu Dec 07, 2006 12:50 pm
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
Posted: Thu Dec 07, 2006 12:57 pm
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.
Posted: Thu Dec 07, 2006 1:05 pm
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
Posted: Thu Dec 07, 2006 1:10 pm
by ok
Try through PHP to get the full path. I think:
Posted: Thu Dec 07, 2006 10:46 pm
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 ??
Posted: Thu Dec 07, 2006 11:27 pm
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.
Posted: Thu Dec 07, 2006 11:30 pm
by neel_basu
No There Are Only A Few Hosts Where php Runs In Safe Mode