166
Programming / Re: problems programming a new text window for cmd.exe/4os2.exe
« on: January 10, 2020, 04:58:52 pm »
>Create a pipe in the parent process
OK. That has been done from the beginning of my project.
>Save the parent processes stdin and stdout to temporary file handles
OK. I have them via DosCreateNPipe parameter.
>and call DosDupHandle on stdin and stdout setting them to the write and read handles of the pipe.
I assume that the Outpipe of my program is the stdin of the child program and reverse. So I have to reverse the assignments in DosDupHandle.
>Then call DosExecProgram and following that restore stdin and stdout in the parent.
I read the docu of DosExecPgm and indeed, I found:
>At that point anything writtten to the pipe's write handle from the parent should go to stdin for the child and anything written to stdout in the child can be read from the pipe's write handle.
I will try it and report here.
OK. That has been done from the beginning of my project.
>Save the parent processes stdin and stdout to temporary file handles
OK. I have them via DosCreateNPipe parameter.
>and call DosDupHandle on stdin and stdout setting them to the write and read handles of the pipe.
I assume that the Outpipe of my program is the stdin of the child program and reverse. So I have to reverse the assignments in DosDupHandle.
>Then call DosExecProgram and following that restore stdin and stdout in the parent.
I read the docu of DosExecPgm and indeed, I found:
Quote
The new process inherits all file handles and pipes of its parent, although not necessarily with the same access rights:
- Files are inherited except for those opened with no inheritance indicated.
- Pipes are inherited.
A child process inherits file handles obtained by its parent process with DosOpen calls that indicated inheritance. The child process also inherits handles to pipes created by the parent process with DosCreatePipe. This means that the parent process has control over the meanings of standard input, output, and error. For example, the parent could write a series of records to a file, open the file as standard input, open a listing file as standard output, and then execute a sort program that takes its input from standard input and writes to standard output.
Because a child process can inherit handles, and a parent process controls the meanings of handles for standard I/O, the parent can duplicate inherited handles as handles for standard I/O. This permits the parent process and the child process to coordinate I/O to a pipe or file. For example, a parent process can create two pipes with DosCreatePipe requests. It can issue DosDupHandle to redefine the read handle of one pipe as standard input (hex 0000), and the write handle of the other pipe as standard output (hex 0001). The child process uses the standard I/O handles, and the parent process uses the remaining read and write pipe handles. Thus, the child process reads what the parent process writes to one pipe, and the parent process reads what the child process writes to the other pipe.
>At that point anything writtten to the pipe's write handle from the parent should go to stdin for the child and anything written to stdout in the child can be read from the pipe's write handle.
I will try it and report here.