Accessing An External Programm
Moderator: General Moderators
- neel_basu
- Forum Contributor
- Posts: 454
- Joined: Wed Dec 06, 2006 9:33 am
- Location: Picnic Garden, Kolkata, India
Accessing An External Programm
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 ??
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 ??
- dibyendrah
- Forum Contributor
- Posts: 491
- Joined: Wed Oct 19, 2005 5:14 am
- Location: Nepal
- Contact:
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 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
- neel_basu
- Forum Contributor
- Posts: 454
- Joined: Wed Dec 06, 2006 9:33 am
- Location: Picnic Garden, Kolkata, India
Here Is My Codes
============
Suppose its My exe Programm made By C Codes
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
============
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);
}
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
- dibyendrah
- Forum Contributor
- Posts: 491
- Joined: Wed Oct 19, 2005 5:14 am
- Location: Nepal
- Contact:
To be able to get the output fo the program executed, just do the following :
In this case, mult.exe must be in the same directory where this script is executing.
Hope this is what you are looking for.
Code: Select all
$output = shell_exe('mult.exe');
print $output;Hope this is what you are looking for.
Code: Select all
$output = shell_exe('mult.exe xyz');see http://computer.howstuffworks.com/c38.htm
- dibyendrah
- Forum Contributor
- Posts: 491
- Joined: Wed Oct 19, 2005 5:14 am
- Location: Nepal
- Contact:
- neel_basu
- Forum Contributor
- Posts: 454
- Joined: Wed Dec 06, 2006 9:33 am
- Location: Picnic Garden, Kolkata, India
I Read That On ('http://computer.howstuffworks.com/c38.htm')
Now Its My C Code
==============
And I Saved/Build It As pass_arg.exe
And Here Is The Out Put In cmd Line Start>run>cmd>
======================================
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 !!!!!!
Now Its My C Code
==============
Code: Select all
#include <stdio.h>
int main(int argc)
{
printf("%d\n",argc);
return 0;
}
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>
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 !!!!!!
I'm not sure what you've read but http://computer.howstuffworks.com/c38.htm shows something different
http://computer.howstuffworks.com/c38.htm wrote:int main(int argc, char *argv[])
neel_basu wrote:int main(int argc)
- neel_basu
- Forum Contributor
- Posts: 454
- Joined: Wed Dec 06, 2006 9:33 am
- Location: Picnic Garden, Kolkata, India
Sorry Sir
Can You Tell Me A Sample Output Of That Programm ??
I Compiled That Programm With That Code in That
===================================
But When I Build That Programm It Was Its Output
======================================
But I Dont Think It Should Be The Output Of That Programm
I Think It Should Print
===============
While Entering
============
In Commandline
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;
}
======================================
Code: Select all
C:\Documents and Settings\Neel_Zit\Desktop\Debug>pass_arg.exe 45 abcd
3
pass_arg.exe
45
abcd
I Think It Should Print
===============
Code: Select all
45
a
b
c
d============
Code: Select all
C:\Documents and Settings\Neel_Zit\Desktop\Debug>pass_arg.exe 45 abcd