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

Laurence Pithie

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 3
  • Posts: 34
    • View Profile
Re: problems programming a new text window for cmd.exe/4os2.exe
« Reply #30 on: January 15, 2020, 01:10:06 am »
It would appear that cmd isn't the signal focus for it's screen group, so it will not process  either the break or the intr signals. A process calls DosSetSignalExceptionFocus to become the signal focus. It looks as if cmd.exe doesn't do this, so it will only respond to the signals if it's the application that has current focus.

Martin Vieregg

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 122
    • View Profile
Re: problems programming a new text window for cmd.exe/4os2.exe
« Reply #31 on: January 15, 2020, 08:30:15 am »
>A process calls DosSetSignalExceptionFocus to become the signal focus.

But I cannot execte CMD.EXE code. I tried to use DosSetSignalExceptionFocus before calling DosExecPgm, but it seems that this property of the parent process is not inherited. DosSetSignalExceptionFocus always refers to the calling process and I cannot hand over a PID in the function call.

Lars

  • Sr. Member
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 45
  • Posts: 484
    • View Profile
Re: problems programming a new text window for cmd.exe/4os2.exe
« Reply #32 on: January 15, 2020, 02:53:14 pm »
I think you will have to use DosStartSession instead of DosExecPgm as you are starting a different app type.
When you do that you can also kill the session that executes CMD.EXE.
You can therefore register a handler for your process and if it fires,just kill the started session.

Lars

  • Sr. Member
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 45
  • Posts: 484
    • View Profile
Re: problems programming a new text window for cmd.exe/4os2.exe
« Reply #33 on: January 15, 2020, 02:57:00 pm »
You kill a session with DosStopSession.

Martin Vieregg

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 122
    • View Profile
Re: problems programming a new text window for cmd.exe/4os2.exe
« Reply #34 on: January 15, 2020, 11:20:39 pm »
I think I cannot run cmd.exe via session by using DosStartSession because only DosExecPgm inherits the standard pipes stdin/stdout/stderr. Meanwhile, I fear we're spinning circles. At the first try, I used DosStartSession and Named Pipes. And I changed to DosExecPgm and unnamed pipes with DosDupHandle with the hope of managing the Ctrl-C Interrupt communication problem. Besides this point, the two ways are basically working. But I have a weak idea that DosExecPgm is the smarter option. In both cases, I can stop it. The DosStartSession variant has got DosStopSession, the DosExecPgm variant DosKillProcess. I cannot believe that there is no solution for sending Ctrl-C to cmd.exe. If noone has got an idea to send Ctrl-C to cmd.exe, I will program a kill option in several steps: One waiting for a finished line output and the harder one with immidiately killing the process. But Ctrl-S should suspend cmd.exe. I can suspend a thread but can I suspend a process? I fear not. And what about sessions? Can I suspend sessions? How does the parent process gets informed if the session ends itseif? I also fear that it is not possible. (With the DosExecPgm variant, I can wait for finishing with DosWaitChild.) Anyway, freezing the output of the parent editor should go. But what happens if the pipe is full? Does the OS suspend the process or do I get an error?


Rich Walsh

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 12
  • Posts: 105
  • ONU! (OS/2 is NOT Unix!)
    • View Profile
Re: problems programming a new text window for cmd.exe/4os2.exe
« Reply #35 on: January 16, 2020, 09:59:58 am »
I cannot believe that there is no solution for sending Ctrl-C to cmd.exe.

Of course there is.

As I understand it, you want the user of your PM-based editor to be able to press Ctrl-C or Ctrl-Break in your app to send a signal exception to cmd.exe. Your problem here is that these two keystrokes have no special meaning in PM and won't generate an exception. They're just keystrokes that show up in your message queue.

When you get one, call DosSendSignalException(pid, exception). 'PID' is the process you DosExec()'d. Exception is XCPT_SIGNAL_INTR or XCPT_SIGNAL_BREAK. I leave it to you to test whether this works.

Martin Vieregg

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 122
    • View Profile
Re: problems programming a new text window for cmd.exe/4os2.exe
« Reply #36 on: January 16, 2020, 02:55:19 pm »
Laurence also assumed that it should work, but it does not.

- I start cmd.exe via DosExecPgm without failure
- I get a valid PID which corresponds to the shown value in the TOP program
- The thread where I call DosExecPgm waits correctly with DosWaitChild
- In the main thread (user input), I call DosSendSignalException with the valid PID and XCPT_SIGNAL_INTR or XCPT_SIGNAL_BREAK
- but DosSendSignalException returns error 205 and the Exception does not reach cmd.exe.

I observe the steps with a log file.

This is the problem what is discussed the last 15 posts and noone has an idea what the problem could be. A lot of reasons for malfunction are eliminated now.

Besides this point, it seems that I have got all other problems solved and the program already works fine.

Dave Yeo

  • Hero Member
  • *****
  • Thank You
  • -Given: 11
  • -Receive: 164
  • Posts: 2302
    • View Profile
Re: problems programming a new text window for cmd.exe/4os2.exe
« Reply #37 on: January 16, 2020, 05:25:20 pm »
Larson Commander seems to be able to do it. The source (C++) is available at https://sourceforge.net/p/lcmd/code/HEAD/tree/,  GPL.

Martin Vieregg

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 122
    • View Profile
Re: problems programming a new text window for cmd.exe/4os2.exe
« Reply #38 on: January 16, 2020, 09:51:19 pm »
>Larson Commander seems to be able to do it.

A very interesting hint. I nearly daily use Larsen Commander. The cmd output window is indeed really interesting. It even supports marking text. I haven't checked it yet under this aspect. In opposite to my program, every command starts a new instance of cmd.exe. cmd.exe and its own PID is seen in GO and TOP. That means that it also starts DosExecPgm.
 
But - what a pity - Ctrl-C Breaks and Ctrl-Break also does not work ! Killing and exiting works. Killing ist clear, but what is exiting (while a long output is running) ? What could be the difference to killing ?This would be an option for Ctrl-C if the classic break does not work.

Anyway, searching a program which has done the job is a goodl way to find the solution.

Dave Yeo

  • Hero Member
  • *****
  • Thank You
  • -Given: 11
  • -Receive: 164
  • Posts: 2302
    • View Profile
Re: problems programming a new text window for cmd.exe/4os2.exe
« Reply #39 on: January 16, 2020, 10:05:13 pm »
CTRL-C works here in Larson Manager. Test case was running a make command and pressing CTRL-C which gave a popup asking which child process to send the break to, choosing the make cmd breaks it as expected. Did crash the program when I repeated it though.

Dave Yeo

  • Hero Member
  • *****
  • Thank You
  • -Given: 11
  • -Receive: 164
  • Posts: 2302
    • View Profile
Re: problems programming a new text window for cmd.exe/4os2.exe
« Reply #40 on: January 16, 2020, 10:14:40 pm »
Perhaps your problem is that you are sending the CTRL-C to cmd.exe instead of the child process that cmd is running, make in my example?

Lars

  • Sr. Member
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 45
  • Posts: 484
    • View Profile
Re: problems programming a new text window for cmd.exe/4os2.exe
« Reply #41 on: January 16, 2020, 11:59:36 pm »
I think I cannot run cmd.exe via session by using DosStartSession because only DosExecPgm inherits the standard pipes stdin/stdout/stderr. Meanwhile, I fear we're spinning circles. At the first try, I used DosStartSession and Named Pipes. And I changed to DosExecPgm and unnamed pipes with DosDupHandle with the hope of managing the Ctrl-C Interrupt communication problem. Besides this point, the two ways are basically working. But I have a weak idea that DosExecPgm is the smarter option. In both cases, I can stop it. The DosStartSession variant has got DosStopSession, the DosExecPgm variant DosKillProcess. I cannot believe that there is no solution for sending Ctrl-C to cmd.exe. If noone has got an idea to send Ctrl-C to cmd.exe, I will program a kill option in several steps: One waiting for a finished line output and the harder one with immidiately killing the process. But Ctrl-S should suspend cmd.exe. I can suspend a thread but can I suspend a process? I fear not. And what about sessions? Can I suspend sessions? How does the parent process gets informed if the session ends itseif? I also fear that it is not possible. (With the DosExecPgm variant, I can wait for finishing with DosWaitChild.) Anyway, freezing the output of the parent editor should go. But what happens if the pipe is full? Does the OS suspend the process or do I get an error?


So why did it work for me ? I could start a session and redirect stdout and stdin without a problem.

Martin Vieregg

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 122
    • View Profile
Re: problems programming a new text window for cmd.exe/4os2.exe
« Reply #42 on: January 17, 2020, 09:39:52 am »
>CTRL-C works here in Larson Manager.

When pressing Ctrl-C in Larsen Commander, I get a menu with four options:
- Ctrl-C Break
- Ctrl-Break
- exit
- kill.

Ctrl-C Break and Ctrl-Break does not work, exit and kill works. My version is 1.6 milestone 3. I run C:\>  dir /s

>So why did it work for me ? I could start a session and redirect stdout and stdin without a problem.

All works fine, but only sending the Ctrl-C exception to the cmd.exe child does not work. This is the only problem.

>Perhaps your problem is that you are sending the CTRL-C to cmd.exe instead of the child process that cmd is running, make in my example?

Yes, meanwhile I have thought about this problem, too. My main program (the editor) creates a thread where cmd.exe gets executed asynchronously, that means the thread calls  DosExecPgm call and this call returns the PID which I need for sending the exception if a user in the editor presses Ctrl-C. Then the thread waits for terminating cmd.exe by using DosWaitChild. I have only one child PID. The thread which calls DosExecPgm and then waits has only a Thread ID (TID), not a PID.

So the main interest should be at the commandline window itself. The window is a PM program and inside, there is a textmode program running. Perhaps I send the exception to the wrong part ? But I have got only one PID. (Perhaps someone can explain it further what cmd.exe is.)

Lars

  • Sr. Member
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 45
  • Posts: 484
    • View Profile
Re: problems programming a new text window for cmd.exe/4os2.exe
« Reply #43 on: January 17, 2020, 05:20:19 pm »
Rich already explained it:
your editor app is a PM app. PM apps know nothing about the special handling for Ctrl-C.
your PM app needs to treat the Ctrl-C combination in its window procedure and do a "DosSendSignalException(pid, exception)". DosExecPgm returns the PID of the program it just started (in your case:cmd.exe).

Silvan Scherrer

  • Full Member
  • ***
  • Thank You
  • -Given: 9
  • -Receive: 9
  • Posts: 174
    • View Profile
Re: problems programming a new text window for cmd.exe/4os2.exe
« Reply #44 on: January 17, 2020, 05:35:16 pm »
Try to send the Signal with this snipped
http://www.edm2.com/index.php/DosSendSignalException
And see if you get the same 205.
kind regards
Silvan
CTO bww bitwise works GmbH

Please help us with donations, so we can further work on OS/2 based projects. Our Shop is at https://www.bitwiseworks.com/shop/index.php