Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

run c program using php

Tags:

c

php

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

like image 338
Kiran Rachamalla Avatar asked Aug 04 '12 12:08

Kiran Rachamalla


People also ask

Can we run C program in Mobile?

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.

What is C language used for?

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 ...


2 Answers

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 ) -->
like image 163
Milind Morey Avatar answered Oct 21 '22 14:10

Milind Morey


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.

like image 41
Quentin Avatar answered Oct 21 '22 13:10

Quentin