Question about process

Started by dexter, June 17, 2012, 09:17:04 PM

Previous topic - Next topic

dexter

I wrote a simple program in linux

#include <stdio.h>

int main ()
{
  char str [80];

    while(1)
    {
        fgets(str, 80, stdin);
        printf("%s",str);
    }

  return 0;
}

saved as 1.c
Quote
gcc 1.c


then there is a a.out



then I want to communicate this a.out with process and pipe...



;; Linux/Unix
(map set '(myin bcout) (pipe))
(map set '(bcin myout) (pipe))

;; launch Unix 'bc' calculator application
(setq pid (process "./a.out" bcin bcout) )

(println pid)

(write myout "hellon")  ; bc expects a line-feed

(setq ret  (read-line myin)  )

(print ret)
;; destroy the process
(destroy pid)



it works at least, as you can see, this little codes is copy from newlisp manual



But I Can not get  any result ,blocked in read-line



why is this happend?

My simple program is just like bc , I inputed something and hit enter key

then it print back what I inputed



But bc got work, So I am confused now

Lutz

#1
This one will work:


#include <stdio.h>

int main ()
{
  char str [80];

    while(1)
    {
        fgets(str, 80, stdin);
        fprintf(stdout,"%s",str);
        fflush(stdout);
    }

  return 0;
}