Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions HTML form to C program
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
1


1
I have this small program which takes input from stdin sample.c

#include<stdio.h>
main()
{
int l=0;
scanf("%d",&l);
printf("\n%d",l);
}
ofcourse! compiled it: cc sample.c and got a.out and i am trying to run it via php like

$runcmd = "./a.out > output.txt";
exec($runcmd,$outp);
print_r($outp);
my problem is i dont have any idea how to give input to this program so that scanf can read that? please help me here!

googling gave some tips like proc_open, popen .... but i couldn't make it.

Thanks in Advance.2

take a look at popen http://se1.php.net/popen

it works a bit like fopen, and when using fwrite, insted of writing to a file you can write to a prosses stdin insted.

$runcmd = "./a.out > output.txt";
$process_stdin = popen($runcmd, 'w');
fwrite($process_stdin, "text to send to process");
pclose($process_stdin);

hacktober fest