Igna wrote:
Hello. I have to write a pipe to joint a GUI in perl and a simulation
program in c. I have read all the docs found in perl.com and now I am
trying to make a test with this simple program. It seems working but it
does not write "bonjour" at the end. Can anybody tell me where my
mistake is? I will be happy for any sample of code for a pipe between c
and perl sent to me too.
Thanks in advance,
Ignazio
#include <stdio.h>
#include <memory.h>
Non-standard header. Not used in code
#include <unistd.h>
Non-standard header. Implies POSIX/Unix code; followup in Unix
development forum
char chaine[7];
Uninitialized array - caution required.
int status;
int main( int argc, char ** argv )
{
/* create the pipe */
int pfd[2];
Uninitialized array - caution required.
>
int pid;
if ((pid = fork()) < 0)
Non-standard function fork() - Implies POSIX/Unix code; followup in
Unix development forum (requires additional include files)
{
printf("fork failed\n");
return 2;
Non-standard return value from main() - only 0, EXIT_SUCCESS and
EXIT_FAILURE are acceptable - value implies POSIX/Unix code; followup
in Unix development forum
}
if (pid == 0)
{
/* child */
close(pfd[0]);
Non-standard function close() - Implies POSIX/Unix code; followup in
Unix development forum
Improper argument passed to function close() - pfd[0] has not been
initialized with any value
write(pfd[1],"bonjour",7);
Non-standard function write() - Implies POSIX/Unix code; followup in
Unix development forum
Improper argument passed to function write() - pfd[1] has not been
initialized with any value
dup2(pfd[1], 1); /* connect the write side with stdout */
Non-standard function dup2() - Implies POSIX/Unix code; followup in
Unix development forum
Improper argument passed to function dup2() - pfd[1] has not been
initialized with any value
close(pfd[1]); /* close the write side */
Non-standard function close() - Implies POSIX/Unix code; followup in
Unix development forum
Improper argument passed to function close() - pfd[1] has not been
initialized with any value
printf("CHAINE FILS %s\n",chaine);
Improper argument passed to function printf() - array chaine[] has not
been initialized with any value
//return 3;
exit(0);
}
else
{
/* parent */
close(pfd[1]); /* close the unused write side */
Non-standard function close() - Implies POSIX/Unix code; followup in
Unix development forum
Improper argument passed to function close() - pfd[1] has not been
initialized with any value
dup2(pfd[0], 0); /* connect the read side with stdin */
Non-standard function dup2() - Implies POSIX/Unix code; followup in
Unix development forum
Improper argument passed to function dup2() - pfd[0] has not been
initialized with any value
read (pfd[0],chaine,7);
Non-standard function read() - Implies POSIX/Unix code; followup in
Unix development forum
Improper argument passed to function read() - pfd[0] has not been
initialized with any value
close(pfd[0]); /* close the read side */
Non-standard function close() - Implies POSIX/Unix code; followup in
Unix development forum
Improper argument passed to function close() - pfd[0] has not been
initialized with any value
printf("CHAINE PARENT %s\n",chaine);
Improper argument passed to function printf() - unless non-standard
function read() has altered it's contents, array chaine[] has not been
initialized with any value
wait(&status);
Non-standard function wait() - Implies POSIX/Unix code; followup in
Unix development forum (requires additional include files)
}
Caution: Missing return value from main() - only 0, EXIT_SUCCESS and
EXIT_FAILURE are acceptable
}
HTH
--
Lew