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");
in PHP and
getopt(argc,argv, "a:");
in C
everything works, but when i pass strings longers than MAX_ARG_STRLEN (131072), it will no longer return 0 instead it returns 127 which is command not found….
is there any other ways to pass string data to a linux executable? or is there any way to overcome the MAX_ARG_STRLEN problem?
You could use
popen()to open a pipe to the executable:Then, as previously suggested, read from
stdinin your C program:It is “safer” to use
popen()rather thanexec('/bin/echo')because you can write characters that would otherwise be interpreted by the shell (&, |, …). Note that the handle returned from PHP’spopen()must be closed withpclose().