Hi all,
I am writing a c program on a unix machine.
I am using popen to open a pipe to run a shell script and get the result
back. I do this several times with success. However, one of the times, I
always get back an error that says "broken pipe". Does anyone know what
causes this and how to fix it?
Sample code...
This one works fine.
strcpy(cmd, "date +%m/%d/%Y");
if ((ptmp = popen(cmd, "r")) != NULL)
{
fgets(dateDumpReceived, 11, ptmp);
pclose(ptmp);
}
else
strcpy(dateReceived, "00/00/0000");
The code that breaks is this...
sprintf(cmd, "isInDB %s %s", customerName, orderNumber);
if ((ptmp = popen(cmd, "r")) != NULL)
{
fgets(response, 1, ptmp);
pclose(ptmp);
}
if (strncmp(response, "Y", 1) != 0)
{
printf("Fatal Error: Customer not found in DB!.\n");
return 1;
}
Looks the same to me...but the second one gives me the "broken pipe"
message. If it matters, the second bit there actually appears first in
the full code.
Can anyone help...?
Thanks!
~kaeli~