470,864 Members | 1,965 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,864 developers. It's quick & easy.

C program and PHP

Hi,

I have written this function in a C program, using Visual Studio. The
PHP script executes fine, but the output is not displayed. I have
been racking my brains for hours trying to figure this one out. The
output from the php program should print to a file called 'out.txt'.
The file is successfully created, but with no content. I am pretty
sure it's the way PHP returns the results. Does anyone have any
ideas? Any help would be most appreciated.

int passCode(void)
{
FILE *phpFile, *out;
size_t len;
char buffer[1000];

phpFile = popen("php -f testing1.php", "r");
if (phpFile)
{
out = fopen("out.txt", "w");
len = fread(buffer, 1, sizeof(buffer), phpFile);
fprintf(out, buffer);
fclose(out);

pclose(phpFile);

return 1;
}
else
{
return 0;
}
}
Jul 17 '05 #1
1 1410
Ben Chivers <be***********@ntlworld.com> wrote:
The output from the php program should print to a file called 'out.txt'.
The file is successfully created, but with no content. I am pretty
sure it's the way PHP returns the results. Does anyone have any
ideas? Any help would be most appreciated.


Sounds like buffering is on in php. No output till you terminate the
popen. See flush and Output Control in the reference.

But why are you using php/C in this horrible way? It might be much
nicer/easier to give php a commandline argument which contains the file
to write to, system() the thing and when system return check if there is
any useful output in the file.

--

Daniel Tryba

Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

22 posts views Thread by edgrsprj | last post: by
11 posts views Thread by christopher diggins | last post: by
1 post views Thread by Eric Whittaker | last post: by
9 posts views Thread by Hemal | last post: by
7 posts views Thread by ibtc209 | last post: by
Banfa
2 posts views Thread by Banfa | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.