how to run c program using php exec()
i have seen many results from google search
it is possible by exec() function
but i am unable to use it
i tried in this way
i wrote a program in c
**myc.c**
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("Hello, world\n");
return 0;
}
**test.php**
<?php
exec('myc.c');
?>
can any one help me pls in this regard i executed this through wamp server by placing in www folder
Android is based on Linux Kernel so it's definitely possible to compile & run C/C++ programs on Android. C is quite cross-platform , so a C Program written in Windows can Run on Linux ( and android ) and vice versa.
C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...
C Program
#include <stdio.h>
int main(int argc, char **argv)
{
if(argv[1])
printf("First arg %d\n", argv[1]);
if(argv[2])
printf("Second arg %d", argv[2]);
return 0;
}
PHP Code
<?php
exec("testone.exe 125 70", $out);
print_r($out);
?>
Combined Output:
<!-- Array ( [0] => First arg 27 [1] => Second arg 27 ) -->
If you want to run a program written in C then you have to run the program and not the source code.
Compile your C into an executable, then call the name of the executable from exec
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With