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

Martin Vieregg

  • Sr. Member
  • ****
  • Posts: 278
  • Karma: +2/-0
    • View Profile
MeShell and PAUSE in a cmd file
« on: April 15, 2020, 05:29:39 pm »
Meanwhile, I have published a stable beta version of MeShell 0.51 (see Utilities). But there's one problem left where I need your help for brainstorming.

PAUSE is a command which is defined in cmd.exe or 4os2.exe. It does not handle Stdin, but it does also not handle normal VIO keyboard input. I do not understand completely how it works, because a key input into the MeShell original VIO window has no effect. It seems that it is compiled completely internally. And this is a problem for MeShell. In comparison to "MORE", where I programmed an expedient substitute, I have no Idea at the moment how to handle the PAUSE problem. I hope that you have ideas how to handle the problem.

Programming a tiny "pause.exe" does not work because cmd.exe executes "pause" directly without checking the PATH directory list for external programs.

Till now, I found a convenient solution for every problem, and I hope that someone here has an idea how to solve this problem.

Pete

  • Hero Member
  • *****
  • Posts: 1281
  • Karma: +9/-0
    • View Profile
Re: MeShell and PAUSE in a cmd file
« Reply #1 on: April 15, 2020, 10:37:52 pm »
Hi Martin

Could you not recompile your pause.exe as a DLL file to be imported/called by your app?


Regards

Pete

Martin Vieregg

  • Sr. Member
  • ****
  • Posts: 278
  • Karma: +2/-0
    • View Profile
Re: MeShell and PAUSE in a cmd file
« Reply #2 on: April 15, 2020, 10:52:01 pm »
Quote
Could you not recompile your pause.exe as a DLL file to be imported/called by your app?

The "PAUSE" command is part of cmd.exe, like "copy" or "dir". In opposite e.g. "xcopy" is an external program "xcopy.exe" and if it would not fit my purpose, I could rewrite and replace it.
The 4os2 source code is available, so I could change it, but I hope that I can handle the problem generally with cmd.exe.

A possible solution would be to ask the user how to handle the cmd file and, as an option, to rewrite it and renaming the original to *.cmd-old and replacing the occurences of "pause" to "pause2" and writing a tiny program "pause2". Or executing a temporary cmd file copy. But I hope that there's a better solution.

It would be already helpful if someone can explain why cmd.exe "Pause" does not accept a VIO keystroke. I don't understand what happens here. You can see the behaviour by typing "PAUSE" in MeShell, then make the VIO window visible, press a key and normally the LED should turn to green and the command "Pause" has finally been executed and a new Prompt appears. But MeShell does not do so. The LED rests red, so the keystroke in the VIO window has not been reached cmd.exe.

Martin Vieregg

  • Sr. Member
  • ****
  • Posts: 278
  • Karma: +2/-0
    • View Profile
Re: MeShell and PAUSE in a cmd file
« Reply #3 on: April 16, 2020, 12:20:34 am »
It seems that the problem is a FALSE ALARM. In a very early version of MeShell (cmdme 0.1) PAUSE did work already. So it seems that it is a newer bug in MeShell. I have also seen that the current MeShell 0.51 does not handle user input in a commandline program anymore. I have only to compare the old code with the current one to find the bug.

Martin Vieregg

  • Sr. Member
  • ****
  • Posts: 278
  • Karma: +2/-0
    • View Profile
Re: MeShell and PAUSE in a cmd file
« Reply #4 on: April 16, 2020, 03:32:06 pm »
Meanwhile I have uploaded MeShell 0.52. The PAUSE problem was a new bug. Even 0.50 worked. (See section utilities).

But there's another related problem:

If a program requires user input via stdin in the same line where an output has placed, like

enter the desired directory name and press ENTER:

MeShell does not show the query, because cmd.exe and 4os2.exe only sends output to stdout if the line has been completed with Return. But both programs send an output without ending Return when the old command has been executed and the new prompt is shown.

With the simple attachment stdin/out based program sample, you can test the behaviour in cmd.exe/4os2.exe and MeShell.

Code: [Select]
[C:\]test1
Enter an expression: hello
You have entered: hello

[C:\]

Do we have access to cmd.exe source code?
I want so send the desire to Netlabs for 4os2.exe. Who is responsible for 4os2.exe Netlabs?

Does anyone has an idea how to force cmd.exe/4os2.exe to spit out the characters which are not shown?

Laurence Pithie

  • Jr. Member
  • **
  • Posts: 62
  • Karma: +1/-0
    • View Profile
Re: MeShell and PAUSE in a cmd file
« Reply #5 on: April 16, 2020, 04:18:50 pm »
While there's no output to stdout until the eol is recieved the cursor position will have changed. Calling VioGetCurPos before issuing a command, check for output on stdout, and if there is no output call VioGetCurPos again and compare the two values. If the values differ then use VioReadCharStr with the two values you have for the cursor position to get the output prompt and display it to the user. It's similar to the logic you used for capturing Vio Output.

Martin Vieregg

  • Sr. Member
  • ****
  • Posts: 278
  • Karma: +2/-0
    • View Profile
Re: MeShell and PAUSE in a cmd file
« Reply #6 on: April 17, 2020, 10:42:09 am »
Laurence,
but the VIO window rests empty. The cursor in the VIO window does not change. I could handle it if it is VIO output and input. But I do not receive redirected stdout in the described case. I thaught that the Vio* calls are completely restricted to the VIO window and not to stdin/stdout ?

Laurence Pithie

  • Jr. Member
  • **
  • Posts: 62
  • Karma: +1/-0
    • View Profile
Re: MeShell and PAUSE in a cmd file
« Reply #7 on: April 17, 2020, 12:34:31 pm »
The standard i/o functions move the Vio cursor. I've attached a simple program, with source, to demonstrate.

Laurence Pithie

  • Jr. Member
  • **
  • Posts: 62
  • Karma: +1/-0
    • View Profile
Re: MeShell and PAUSE in a cmd file
« Reply #8 on: April 17, 2020, 01:51:10 pm »
Quote
But I do not receive redirected stdout in the described case
You need to check for the change in the cursor position in the child/helper application, then use VioReadCharStr to get the prompt text and send that text through the pipe to the main application.

Martin Vieregg

  • Sr. Member
  • ****
  • Posts: 278
  • Karma: +2/-0
    • View Profile
Re: MeShell and PAUSE in a cmd file
« Reply #9 on: April 17, 2020, 02:06:08 pm »
Thank you for the sample. Sorry, but it does not. You forgot that stdout is piped to the editor.

Code: [Select]
[H:\cursor]cursorpos
Hello World!
Initial cursor position: Column 0, Row 24
Final cursor position: Column 12, Row 24

[H:\cursor]cursorpos >out.txt

[H:\cursor]type out.txt
Hello World!
Initial cursor position: Column 0, Row 24
Final cursor position: Column 0, Row 24

Laurence Pithie

  • Jr. Member
  • **
  • Posts: 62
  • Karma: +1/-0
    • View Profile
Re: MeShell and PAUSE in a cmd file
« Reply #10 on: April 17, 2020, 02:40:35 pm »
Stdout is read by the child program and piped to the editor. You check for a prompt in the child program.
Parent pipes command to child program
child program checks cursor position
child program writes command to stdout
child program checks for output on stdout
    if there is no output on stodut
           check cursor position
           compare cursor position with original position

Martin Vieregg

  • Sr. Member
  • ****
  • Posts: 278
  • Karma: +2/-0
    • View Profile
Re: MeShell and PAUSE in a cmd file
« Reply #11 on: April 17, 2020, 04:04:42 pm »
I do not understand what you mean. I think the explanaition was too short. What is the child program? The helper or the external program which is executed, for example your sample program?

Do you think that the helper should read what happens in the pipe? (How can I do that?) But this provides that the output already happens, and I fear that the pipe is only running after eol / Return and before a line is finished, also the helper will see nothing.

At the moment, the helper program only opens the pipes on the "cmd side" which are created by MeShell and the cmd stdout/err/in is redirected to the pipes. After initializing, the helper doesn't make anything with the pipes. When terminating cmd.exe, the helper closes the pipes and terminates itself. Of course, I could add some functionality, but at the moment I do not understand what to do.

Martin Vieregg

  • Sr. Member
  • ****
  • Posts: 278
  • Karma: +2/-0
    • View Profile
Re: MeShell and PAUSE in a cmd file
« Reply #12 on: April 20, 2020, 12:52:31 am »
Meanwhile, I've updated MeShell to version 0.54.
 MeShell.zip (650 kB)

If the UNZIP utility asks the user, the query is sent via STDERR. In 0.54, this works now perfect. But if a query is sent via STDOUT, it still does not work.

I have got an interesting sample program
Code: [Select]
#include <stdio.h>
main () {
  char Expression[200];
  printf ("Enter first expression: "); scanf ("%s", Expression);
  printf ("You have entered: %s\n", Expression);
  printf ("\n");
  printf ("(Now query with Stderr)\n");
  fprintf (stderr, "Enter second expression: "); scanf ("%s", Expression);
  printf ("You have entered: %s\n", Expression);
}

and in MeShell, the second query comes first. The order comes false through the two pipes.
Perhaps to omit the problem the query in UNZIP is sent via Stderr.

Martin Vieregg

  • Sr. Member
  • ****
  • Posts: 278
  • Karma: +2/-0
    • View Profile
Re: MeShell and PAUSE in a cmd file
« Reply #13 on: April 21, 2020, 12:46:43 pm »
Still the stdout problem of a query: Meanwhile, I've tested what happens if the helper sends characters to MeShell. But it does not has an effect, I see the helper output immediately in MeShell, and the line which should be shown from the user program still does not appear.

I found out that in Windows 10 the new written commandline pauses 3 seconds before the query is shown. (e.g. "copy" a file to a destination where a file with the same name exists). So it seems the Windows programmers had to fight with the same problem and also made a "dirty hack" which I am looking for. "UNZIP" query (with the query via stderr) comes immediately.

P. S. The Windows 10 commandline has also limits: 32767 lines.

Martin Vieregg

  • Sr. Member
  • ****
  • Posts: 278
  • Karma: +2/-0
    • View Profile
Re: MeShell and PAUSE in a cmd file
« Reply #14 on: April 22, 2020, 10:35:59 am »
I put the question to stackoverflow forum. Let's see what happens.