Page 1 of 5
Accessing An External Programm
Posted: Wed Dec 06, 2006 9:37 am
by neel_basu
Hello Everybody
Would Anyone Please Help Me?? I Wanna Do The Following Thing?
I am Using Windows O/S I Have A .exe File That Takes A
String And Then do Some Job.
After That Prints Another String.
And Thats Made By C
And I Wanna Do The Following Job Through php
I wanna Run That .exe File in Background & Then Pass a
String To It After That I Wanna Get The Output Resultant String From The exe File.
So Anyone Please Tell Me How Can I Do It ??
Posted: Wed Dec 06, 2006 10:01 am
by Corvin
You can do this with
exec().
Posted: Wed Dec 06, 2006 10:27 am
by dibyendrah
There are many ways to get it done.
Please see these functions in the php manual:
1. exec()
2. shell_exec()
3. passthru()
4. system()
5. escapeshellcmd()
6. escapeshellarg()
7. proc_open()
8. proc_close()
9. proc_get_status()
Simple execution of program can be done by exec(), shell_exec() etc. Please see the manual and use according to your needs.
Cheers,
Dibyendra
PLease
Posted: Wed Dec 06, 2006 11:57 am
by neel_basu
Hello
Would You Please PLease Send Me A Sample Simple Code To Do This Job Under Windows And Linux.
Posted: Wed Dec 06, 2006 12:02 pm
by Corvin
Just have a look at the manual pages and the user comments.

Posted: Wed Dec 06, 2006 12:07 pm
by neel_basu
Actually I Have Looked Over The php.net Manual
But It Was Linux Based And I Dont Know Linux And I Didnt Find Any exec() Using An exe File So Please Tell Me Send Me A Sample Code
Posted: Wed Dec 06, 2006 12:13 pm
by neel_basu
Here Is My Codes
============
Suppose its My exe Programm made By C Codes
Code: Select all
#include <stdio.h>
#include <conio.h>
int x;
void main(void)
{
scanf("%d",&x);
printf("%d",x*5);
}
And Then Compile It And Then Build It To Make mult.exe
So How Can I Pass An Integer To This mult.exe Through php And Get The Result Integer On A Windows Server ??
Through php ?
Would You Please Send A Sample php Code ?? PLease Please
Posted: Wed Dec 06, 2006 11:49 pm
by dibyendrah
To be able to get the output fo the program executed, just do the following :
Code: Select all
$output = shell_exe('mult.exe');
print $output;
In this case, mult.exe must be in the same directory where this script is executing.
Hope this is what you are looking for.
Posted: Thu Dec 07, 2006 12:04 am
by neel_basu
Then How Can I Pass The Value Of x To mult.exe !
Posted: Thu Dec 07, 2006 12:08 am
by volka
Code: Select all
$output = shell_exe('mult.exe xyz');
But your c program has to read the argument(s) - it does not yet.
see
http://computer.howstuffworks.com/c38.htm
Posted: Thu Dec 07, 2006 12:31 am
by dibyendrah
neel_basu wrote:Then How Can I Pass The Value Of x To mult.exe !
You must make the program to accept the arguments in the mail function of C program.
Your C program must be able to capture argv arguments. I guess that will solve your problem.
Posted: Thu Dec 07, 2006 4:43 am
by neel_basu
I Read That On ('
http://computer.howstuffworks.com/c38.htm')
Now Its My C Code
==============
Code: Select all
#include <stdio.h>
int main(int argc)
{
printf("%d\n",argc);
return 0;
}
And I Saved/Build It As pass_arg.exe
And Here Is The Out Put In cmd Line Start>run>cmd>
======================================
Code: Select all
C:\Documents and Settings\Neel_Zit\Desktop\Debug>pass_arg.exe
1
C:\Documents and Settings\Neel_Zit\Desktop\Debug>pass_arg.exe 54
2
C:\Documents and Settings\Neel_Zit\Desktop\Debug>pass_arg.exe 25654
2
C:\Documents and Settings\Neel_Zit\Desktop\Debug>
I Compiled It With Microsoft VC++
And Its Not Giving The Expected Result
It Should Output 54 If I Pass Argument 54 But It Makes An Output Of 2 Always
If There Is Any Arguments Passed To It Else The Output is 1
Please Tell Me How I Can Solve This Problem !!!!!!
Posted: Thu Dec 07, 2006 4:52 am
by volka
I'm not sure what you've read but
http://computer.howstuffworks.com/c38.htm shows something different
neel_basu wrote:int main(int argc)
Posted: Thu Dec 07, 2006 5:02 am
by neel_basu
Sorry Sir
Can You Tell Me A Sample Output Of That Programm ??
I Compiled That Programm With That Code in That
===================================
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;
}
But When I Build That Programm It Was Its Output
======================================
Code: Select all
C:\Documents and Settings\Neel_Zit\Desktop\Debug>pass_arg.exe 45 abcd
3
pass_arg.exe
45
abcd
But I Dont Think It Should Be The Output Of That Programm
I Think It Should Print
===============
While Entering
============
Code: Select all
C:\Documents and Settings\Neel_Zit\Desktop\Debug>pass_arg.exe 45 abcd
In Commandline
Posted: Thu Dec 07, 2006 5:31 am
by volka
No, the arguments are separated by whitespaces.
argument #0 is the program name
45 is argument #1
abcd is argument #2
-> 3 arguments
The output
C:\Documents and Settings\Neel_Zit\Desktop\Debug>pass_arg.exe 45 abcd
3
pass_arg.exe
45
abcd
is correct