From 9e9d35683724fc765624b527b4ca3cf86c27ddbf Mon Sep 17 00:00:00 2001 From: gautam20863 <56150963+gautam20863@users.noreply.github.com> Date: Sat, 3 Oct 2020 23:53:09 +0530 Subject: [PATCH 1/2] Create HTML form to C program --- HTML form to C program | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 HTML form to C program diff --git a/HTML form to C program b/HTML form to C program new file mode 100644 index 0000000..8e8b6a3 --- /dev/null +++ b/HTML form to C program @@ -0,0 +1,32 @@ +1 + + +1 +I have this small program which takes input from stdin sample.c + +#include +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); From af61d50c9ebb0eee70ecfb96fa264a25844ef35c Mon Sep 17 00:00:00 2001 From: gautam20863 <56150963+gautam20863@users.noreply.github.com> Date: Sat, 3 Oct 2020 23:54:12 +0530 Subject: [PATCH 2/2] Update HTML form to C program created file for hacktober fest --- HTML form to C program | 2 ++ 1 file changed, 2 insertions(+) diff --git a/HTML form to C program b/HTML form to C program index 8e8b6a3..278c1e7 100644 --- a/HTML form to C program +++ b/HTML form to C program @@ -30,3 +30,5 @@ $runcmd = "./a.out > output.txt"; $process_stdin = popen($runcmd, 'w'); fwrite($process_stdin, "text to send to process"); pclose($process_stdin); + +hacktober fest