Author Topic: problems programming a new text window for cmd.exe/4os2.exe  (Read 38687 times)

Martin Vieregg

  • Sr. Member
  • ****
  • Posts: 278
  • Karma: +2/-0
    • View Profile
Re: problems programming a new text window for cmd.exe/4os2.exe
« Reply #45 on: January 17, 2020, 08:15:32 pm »
Silvan, a good idea. I compiled the simple text program SendException.exe.

Executing without parameter shows an help text:
sendexception.exe sends an exception to a PID. Enter the PID value in decimal first and the Execption type as second parameter.
Sample:  sendexception 197 2
INTR=1 BREAK=2 KILL=4


To recognize the cmd.exe session to observate, run go.exe in the cmd session you want to identify: GO 1.5
The PID we need is in the first row in the line of CMD.EXE, where GO.EXE is shown as child.

In this window, I run "dir /s" which takes a lot of time.
I tried the following input and I got:

Code: [Select]
[C:\]sendexception 106 1
DosSendSignalException returns 205

[C:\]sendexception 106 2
DosSendSignalException returns 209

[C:\]sendexception 106 4
DosSendSignalException returns 205

So the behaviour corresponds to my main program. Now the question is how to send these exceptions to cmd.exe. 209 means ERROR_INVALID_SIGNAL_NUMBER  what is completely suspect to me. 205 means ERROR_NO_SIGNAL_SENT, see the link Silvan posted above.

Andreas Schnellbacher

  • Hero Member
  • *****
  • Posts: 827
  • Karma: +14/-0
    • View Profile
Re: problems programming a new text window for cmd.exe/4os2.exe
« Reply #46 on: January 17, 2020, 09:01:57 pm »
Sending the break signal doesn't work in EPM either. But you can send an exception to the parent thread/process instead. That stops also the child process.

I've just checked this with dir /s executed from an EPM command shell window. In plain EPM, the ProcessBreak command (Ctrl+Break) won't stop the output of CMD.EXE. That's also visible in monitoring the CPU load. In NEPMD, it's possible to kill (and restart) the process that started CMD.EXE and it stops immediately, also visible by the CPU load.


OS4User

  • Sr. Member
  • ****
  • Posts: 406
  • Karma: +10/-0
    • View Profile
Re: problems programming a new text window for cmd.exe/4os2.exe
« Reply #47 on: January 17, 2020, 10:25:54 pm »
But DosSendSignalException still returns 205.

DosSendSignalException will return 205 if it receives PID other than PID of child process.

Martin Vieregg

  • Sr. Member
  • ****
  • Posts: 278
  • Karma: +2/-0
    • View Profile
Re: problems programming a new text window for cmd.exe/4os2.exe
« Reply #48 on: January 17, 2020, 10:41:49 pm »
>In NEPMD, it's possible to kill (and restart) the process that started CMD.EXE and it stops immediately, also visible by the CPU load.

Yes, killing and restarting will be possible (it will feel quite similar). This will be only a substitute hack if the behaviour I hope for is definitely not possible.

Another possibility is to run the child synchronous and sending the signal to the parent program PID. I tried it, but now DosSendSignalException returns 1.

>DosSendSignalException will return 205 if it receives PID other than PID of child process.
But I send the signal to the child process (81 in this case).

GO.EXE output is intersting in this case:

Code: [Select]
GO! v1.2 (Rev. 93/11/27)
(c) 1993 by Carsten Wimmer

             Parent           Num. of
Process ID Process ID Session Threads Priority Name
 Dec  Hex   Dec  Hex  Dec Hex
---------- ---------- ------- ------- -------- ---->
  51   33     0    0   21  15     1     0200   CUPSD.EXE
  46   2e     0    0   20  14     1     0200   SOCKTIDY.EXE
(...)
  32   20     1    1    1   1    30     0200     PMSHELL.EXE
  80   50    32   20   24  18     4     0200       MSHELL.EXE
  81   51    80   50   24  18     1     0200         CMD.EXE

MShell is my parent program (I will change the name later). It executes its child CMD.EXE. Nevertheless, error 205 is returned.

OS4User

  • Sr. Member
  • ****
  • Posts: 406
  • Karma: +10/-0
    • View Profile
Re: problems programming a new text window for cmd.exe/4os2.exe
« Reply #49 on: January 17, 2020, 11:08:33 pm »
>DosSendSignalException will return 205 if it receives PID other than PID of child process.
But I send the signal to the child process (81 in this case).

can you give me kind of test   to run on my system ?

Laurence Pithie

  • Jr. Member
  • **
  • Posts: 62
  • Karma: +1/-0
    • View Profile
Re: problems programming a new text window for cmd.exe/4os2.exe
« Reply #50 on: January 17, 2020, 11:59:39 pm »
The sample programs for the various DosException calls on edm2 all exhibit the same result.
http://www.edm2.com/index.php/DosSendSignalException Sends a signal exception to a process using it's pid. Howver sending the signal to the DosSetExceptionHandler, DosSetSignalExceptionFocus or DosAcknowledgeSignalException examples result in an error 205.
http://www.edm2.com/index.php/DosSetExceptionHandler
http://www.edm2.com/index.php/DosSetSignalExceptionFocus
http://www.edm2.com/index.php/DosAcknowledgeSignalException

Martin Vieregg

  • Sr. Member
  • ****
  • Posts: 278
  • Karma: +2/-0
    • View Profile
Re: problems programming a new text window for cmd.exe/4os2.exe
« Reply #51 on: January 18, 2020, 09:15:07 am »
>can you give me kind of test to run on my system ?

See Reply #45. Here you can download SendException.exe. It is compiled with WDsibyl (Pascal). Meanwhile, I have compiled the EDM sample code with a C compiler, same result. The behaviour is the same like in my main program.

If SendSignalException and its relatives does not work at all, what is the purpose of these functions? Is it a bug? Does anyone has a Warp 3 (or 2.1) installation running?

We could send the exception to a different program to see if the problem is located in cmd.exe. I am not very familar with Exceptions. What does the Ctrl-C exception do in the target program? Is it like a keyboard input of Ctrl-C ? E.g. In ME Editor Ctrl-C is Page Down with Wordstar keyboard layout (Options - Settings - General). I haven't programmed receiving exceptions from outside yet.

OS4User

  • Sr. Member
  • ****
  • Posts: 406
  • Karma: +10/-0
    • View Profile
Re: problems programming a new text window for cmd.exe/4os2.exe
« Reply #52 on: January 18, 2020, 09:22:56 am »
>can you give me kind of test to run on my system ?
See Reply #45. Here you can download SendException.exe.

I would like to receive a copy of MShell to try to send a signal to its child - cmd.exe as shown in Reply #45.  I would try to get the answer why you received 205 in this case.

Martin Vieregg

  • Sr. Member
  • ****
  • Posts: 278
  • Karma: +2/-0
    • View Profile
Re: problems programming a new text window for cmd.exe/4os2.exe
« Reply #53 on: January 18, 2020, 06:54:14 pm »
>I would like to receive a copy of MShell

Now I have fixed some other bugs and I can show the current state of the project to others. I have changed the name now to CmdMe because MShell is already occupied (a PMShell substitute for OS/2). If anyone has got a better name for the program, please tell it here.

In the attachment, you will find the current exe (version number 0.10). I have written all important stuff into the readme text file.

If we totally fail with sending exceptions to cmd.exe, I will run cmd.exe synchronously and suspend and kill the thread. This will work, but is not the preffered solution.

OS4User

  • Sr. Member
  • ****
  • Posts: 406
  • Karma: +10/-0
    • View Profile
Re: problems programming a new text window for cmd.exe/4os2.exe
« Reply #54 on: January 18, 2020, 08:53:12 pm »
In the attachment, you will find the current exe (version number 0.10). I have written all important stuff into the readme text file.

Well, I have tested you CmdMe - everything is working as expected:

DosSendSignalException returns 205 because new processes  are _NOT_ direct children of CmdMe.   Even I use /sync key.

You can easily check this fact  with Theseus.


Martin Vieregg

  • Sr. Member
  • ****
  • Posts: 278
  • Karma: +2/-0
    • View Profile
Re: problems programming a new text window for cmd.exe/4os2.exe
« Reply #55 on: January 19, 2020, 12:08:33 am »
>because new processes  are _NOT_ direct children of CmdMe

How do I have to execute cmd.exe so it gets a direct children of my program?

OS4User

  • Sr. Member
  • ****
  • Posts: 406
  • Karma: +10/-0
    • View Profile
Re: problems programming a new text window for cmd.exe/4os2.exe
« Reply #56 on: January 19, 2020, 12:28:08 pm »
>because new processes  are _NOT_ direct children of CmdMe

How do I have to execute cmd.exe so it gets a direct children of my program?

I am not an expert - but enclosed example gives me direct child, so DosSendSignalException returns ok  - pls check.

I was not able to get direct child using DosStartSession  -  have to learn out more.


Martin Vieregg

  • Sr. Member
  • ****
  • Posts: 278
  • Karma: +2/-0
    • View Profile
Re: problems programming a new text window for cmd.exe/4os2.exe
« Reply #57 on: January 19, 2020, 05:33:49 pm »
I think that DosStartSession is the wrong way because Sessions can include several processes and we need to get the two processes as close as possible.

It tried your sample programs and they indeed work.
The differences to my program are:

- They are running in one single cmd window. I have got a PM app (the parent editor) and a child (cmd.exe) which is not a PM program.
- I am starting DosExecPgm from a thread, your sample program has no theads.

I will now modify your parent send program to a PM app and I will see what happen.
Then I will try to execute the child from the main thread in my program.

Hope we find the reason why your program works and mine not.

Wim Brul

  • Sr. Member
  • ****
  • Posts: 295
  • Karma: +25/-0
    • View Profile
    • Wim's home page
Re: problems programming a new text window for cmd.exe/4os2.exe
« Reply #58 on: January 19, 2020, 07:47:13 pm »
Hi Martin,

I think that DosStartSession is the wrong way because Sessions can include several processes and we need to get the two processes as close as possible.

I don' think so. Using DosStartSession() is the only way to go:

You must use DosStartSession() to start your non-PM process from your PM process.

Within your non-PM process you may then use DosExecPgm() to invoke the Command Processor.   

Your non-PM process may then use DosSendSignalException() to that Command Processor process.

You will have to find a way to signal this request from your PM process to your non-PM process.

One could think of using a system semaphore like e.g. \SEM32\STOPTHAT to do that.

Wim Brul

Martin Vieregg

  • Sr. Member
  • ****
  • Posts: 278
  • Karma: +2/-0
    • View Profile
Re: problems programming a new text window for cmd.exe/4os2.exe
« Reply #59 on: January 19, 2020, 11:17:05 pm »
Wim,
that sounds very plausible. Your description means, exceptions can only be sent from a non-PM process to a non-PM process?

If I understand the DosSendSignalException docu right, the relationship between the processes (child or not) does not matter.

Quote
DosSendSignalException sends either an XCPT_SIGNAL_INTR (Ctrl+C) or an XCPT_SIGNAL_BREAK (Ctrl+Break) signal exception to another process.
But I tried to run os4users parent and child exe from different sessions and the post does not reach the "child" anymore. So it indeed seems that a relationship is necessary.

So I could start two non-pm programs, the cmd.exe and a text-based helper exe which simply sends the message forward to cmd.exe.

Meanwhile, I have tried that both non-pm programs are childs of my PM program and are started via DosExecPgm (asynchronous to get the PID). The parent can tell the helper the PID of the brother/sister. This doesn't work, too. That means, the editor has to execute the helper and the helper has to execute cmd.exe. So my editor gets a grandparent. I'll try this and report here.

Wim, why do you think that I need to implement a new session? Cmd.exe currently runs in the same session as the parent editor.

What is a good tutorial for semaphores with OS/2 ? In my german OS/2 programmers book, semaphores are missing.
« Last Edit: January 20, 2020, 09:25:26 am by Martin Vieregg »