Question about process

Q&A's, tips, howto's
Locked
dexter
Posts: 74
Joined: Fri Nov 11, 2011 12:55 am

Question about process

Post 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

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: Question about process

Post 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;
}

Locked