Page 1 of 1

Question about process

Posted: Mon Jun 18, 2012 4:17 am
by dexter
I wrote a simple program in linux

Code: Select all

#include <stdio.h>

int main ()
{
  char str [80];

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

  return 0;
}
saved as 1.c
gcc 1.c
then there is a a.out

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

Code: Select all

;; 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 "hello\n")  ; 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

Re: Question about process

Posted: Tue Jun 19, 2012 3:53 pm
by Lutz
This one will work:

Code: Select all

#include <stdio.h>

int main ()
{
  char str [80];

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

  return 0;
}