Under Linux ,if I want to pass pure string from PHP to C, how do i do that? what I\'ve tried do far is:
exec(\"./myexec.bin -a mystring\");
You could use popen() to open a pipe to the executable:
$fp = popen('./myexec.bin', 'w');
fwrite($fp, $data);
pclose($fp);
Then, as previously suggested, read from stdin
in your C program:
fopen(stdin, "r");
// ...
It is "safer" to use popen()
rather than exec('/bin/echo')
because you can write characters that would otherwise be interpreted by the shell (&, |, ...). Note that the handle returned from PHP's popen()
must be closed with pclose()
.