Re: Why does a Bash shell script write prompts followed by reads and do it right?

2015-09-02 Thread Bob Proulx
Robert Parker wrote: > fputs(shortprompt, stdout); > fflush(stdin); Uhm... fflush'ing stdin? That doesn't make sense. Obviously you meant to flush stdout. fputs(shortprompt, stdout); fflush(stdout); That is likely the specific problem. Unfortunately I have no

Re: Why does a Bash shell script write prompts followed by reads and do it right?

2015-09-02 Thread Ángel González
Robert Parker wrote: > Yet when I attempt the same in a C program, the system always writes > 2 prompts, then waits for a read. > Does not matter if I write(1, "..."); read(0, number, buffer); or use > fputs("...", stdout); fgets(. > The result is the same. > And I have tried using readline

Re: Why does a Bash shell script write prompts followed by reads and do it right?

2015-09-02 Thread Robert Parker
Thanks guys. Code supplied: static void getuserinput(char *prompt, char *reply); static int getans(char *prompt, char *choices); int main(int argc, char **argv) { char namebuf[NAME_MAX]; char typebuf[NAME_MAX]; char defltbuf[NAME_MAX]; char codebuf[NAME_MAX]; char *eols =

Re: Why does a Bash shell script write prompts followed by reads and do it right?

2015-09-01 Thread Robert Parker
On Tue, Sep 1, 2015 at 12:34 AM, John McKown wrote: > Not a bug, so likely the wrong forum. > > Have you tried doing a fflush() after the fputs()? I.e. something to tell > the Kernel to "write this out immediately!". In the case of write(), I > think you need to use

Re: Why does a Bash shell script write prompts followed by reads and do it right?

2015-09-01 Thread Bob Proulx
John McKown wrote: > Not a bug, so likely the wrong forum. Agreed. > Have you tried doing a fflush() after the fputs()? I.e. something to tell > the Kernel to "write this out immediately!". Almost. It is the C library libc that buffers output with fputs() not the kernel. The libc normally

Re: Why does a Bash shell script write prompts followed by reads and do it right?

2015-09-01 Thread Bob Proulx
Robert Parker wrote: > Yet when I attempt the same in a C program, the system always writes 2 > prompts, then waits for a read. This isn't a C list. But if you don't show us the code then no one can give good help. If you write, read, write and then it *must* try the read before the second

Why does a Bash shell script write prompts followed by reads and do it right?

2015-08-31 Thread Robert Parker
A trivial script example that just works: #!/bin/bash # echo a prompt and write the user's response to a file. echo "Enter variable name: " read ans echo "$ans" > tmpfil echo "Enter variable type: " read ans echo "$ans" >> tmpfil echo "Enter variable default value: " read ans echo "$ans" >>

Re: Why does a Bash shell script write prompts followed by reads and do it right?

2015-08-31 Thread John McKown
Not a bug, so likely the wrong forum. Have you tried doing a fflush() after the fputs()? I.e. something to tell the Kernel to "write this out immediately!". In the case of write(), I think you need to use the O_SYNC flag in the open() call. On Mon, Aug 31, 2015 at 11:25 AM, Robert Parker