Author Topic: MeShell and PAUSE in a cmd file  (Read 11966 times)

Martin Vieregg

  • Sr. Member
  • ****
  • Posts: 278
  • Karma: +2/-0
    • View Profile
Re: MeShell and PAUSE in a cmd file
« Reply #15 on: April 22, 2020, 03:45:33 pm »
Now I am very close to a solution. Someone answered that I have to use fflush(). But fflush(mystream) is Standard C and requires a stream, not an OS/2 HFILE which is opened via DosOpen(). Is there a comparible call for OS/2 HFILE to flush the buffer ? The editor can detect the problem and the helper calls a flush call for stdout.

Lars

  • Hero Member
  • *****
  • Posts: 1298
  • Karma: +65/-0
    • View Profile
Re: MeShell and PAUSE in a cmd file
« Reply #16 on: April 22, 2020, 05:03:53 pm »
DosResetBuf.

Why don't you just read the OS/2 programming doc ?

Martin Vieregg

  • Sr. Member
  • ****
  • Posts: 278
  • Karma: +2/-0
    • View Profile
Re: MeShell and PAUSE in a cmd file
« Reply #17 on: April 22, 2020, 07:20:39 pm »
Yes, I did it, but I tried to find something with "flush".... Thank you.
But anyway, exeuting DosResetBuffer in the helper app has no effect. I also tried to DosClose and DosOpen the named pipe. Also no effect. I really wonder how other command-line frontends do the job.

Martin Vieregg

  • Sr. Member
  • ****
  • Posts: 278
  • Karma: +2/-0
    • View Profile
Re: MeShell and PAUSE in a cmd file
« Reply #18 on: May 12, 2020, 12:14:22 pm »
I realized now that the "fflush" command has to be placed in the user program. Stdout is always buffered when redirecting, Stderr is not. That is the problem that stderr output can happen before the stdout output. I have got an extreme example, see attachment. I wrote the sample for testing colored output and the stderr output is shown 4 lines before it should be shown.

So that means that all programmers which are writing stdout and stderr or use user queries have to flush stdout before performing a stdin:

Code: [Select]
  char Expression[200];
  printf ("Enter an expression: "); fflush (stdout); scanf ("%s", Expression);
  printf ("You have entered: %s\n", Expression);

  flush (stdout); fprintf (stderr, "An error has occured.");

MeShell has been updated to 0.61. See here