VSE - Redirect Standard input/output 
Author Message
 VSE - Redirect Standard input/output

Hi,

I'm trying to re-direct the standard input/output from a child process back
to the parent process. (e.g creator of the child process, process is created
using the #createProcess: API call )

MSDN has a few samples on how to do this, e.g creating a pipe, assign this
tothe startupinfo, and perfrom a read on this.... Al goes well until i do a
read.. the parent process then hangs, and i must kill this via taksmanager..

Anyone tried this before ?

Regards,
Fred

Code the create the pipe:

 hReadPipe :=  ExternalLong new.
 hWritePipe := ExternalLong new.
 KernelLibrary createPipe: hReadPipe asParameter writePipe: hWritePipe
asParameter pipeAttr: nil size: 0.
 hReadPipe := FileHandle fromInteger: hReadPipe asInteger.
 hWritePipe := FileHandle fromInteger: hWritePipe asInteger.

startupInfo := ( SelfDefinedStructure named: 'STARTUPINFO')
      flags: StartfUsestdhandles;
       hStdOutput: hWritePipe;
  yourself

To read i do

buffer := String new: 100.
hReadPipe read: buffer size into: buffer



Fri, 08 Oct 2004 08:11:24 GMT  
 VSE - Redirect Standard input/output
Hi,
you will probably have to setup the handle to be inheritable by the child
process.
In my application I call
 | hDup |
 hDup := ExternalLong new.
 (KernelLibrary
  duplicateHandle: KernelLibrary getCurrentProcess
  handle: hWritePipe
  process: KernelLibrary getCurrentProcess
  thandle: hDup
  access: 0
  inherit: true
  options: DuplicateSameAccess | DuplicateCloseSource) ifFalse: [ self
osError ].
  ^hDup asInteger
and put hDup into the startup info.
otherwise the client does not have access to the pipe, it cannot write to it
and your "read" call blocks indefinitely.

Manfred

Quote:
> Hi,

> I'm trying to re-direct the standard input/output from a child process
back
> to the parent process. (e.g creator of the child process, process is
created
> using the #createProcess: API call )

> MSDN has a few samples on how to do this, e.g creating a pipe, assign this
> tothe startupinfo, and perfrom a read on this.... Al goes well until i do
a
> read.. the parent process then hangs, and i must kill this via
taksmanager..

> Anyone tried this before ?

> Regards,
> Fred

> Code the create the pipe:

>  hReadPipe :=  ExternalLong new.
>  hWritePipe := ExternalLong new.
>  KernelLibrary createPipe: hReadPipe asParameter writePipe: hWritePipe
> asParameter pipeAttr: nil size: 0.
>  hReadPipe := FileHandle fromInteger: hReadPipe asInteger.
>  hWritePipe := FileHandle fromInteger: hWritePipe asInteger.

> startupInfo := ( SelfDefinedStructure named: 'STARTUPINFO')
>       flags: StartfUsestdhandles;
>        hStdOutput: hWritePipe;
>   yourself

> To read i do

> buffer := String new: 100.
> hReadPipe read: buffer size into: buffer



Sat, 09 Oct 2004 16:17:19 GMT  
 VSE - Redirect Standard input/output
Thanks!

Regards,
Fred


Quote:
> Hi,
> you will probably have to setup the handle to be inheritable by the child
> process.
> In my application I call
>  | hDup |
>  hDup := ExternalLong new.
>  (KernelLibrary
>   duplicateHandle: KernelLibrary getCurrentProcess
>   handle: hWritePipe
>   process: KernelLibrary getCurrentProcess
>   thandle: hDup
>   access: 0
>   inherit: true
>   options: DuplicateSameAccess | DuplicateCloseSource) ifFalse: [ self
> osError ].
>   ^hDup asInteger
> and put hDup into the startup info.
> otherwise the client does not have access to the pipe, it cannot write to
it
> and your "read" call blocks indefinitely.

> Manfred


> > Hi,

> > I'm trying to re-direct the standard input/output from a child process
> back
> > to the parent process. (e.g creator of the child process, process is
> created
> > using the #createProcess: API call )

> > MSDN has a few samples on how to do this, e.g creating a pipe, assign
this
> > tothe startupinfo, and perfrom a read on this.... Al goes well until i
do
> a
> > read.. the parent process then hangs, and i must kill this via
> taksmanager..

> > Anyone tried this before ?

> > Regards,
> > Fred

> > Code the create the pipe:

> >  hReadPipe :=  ExternalLong new.
> >  hWritePipe := ExternalLong new.
> >  KernelLibrary createPipe: hReadPipe asParameter writePipe: hWritePipe
> > asParameter pipeAttr: nil size: 0.
> >  hReadPipe := FileHandle fromInteger: hReadPipe asInteger.
> >  hWritePipe := FileHandle fromInteger: hWritePipe asInteger.

> > startupInfo := ( SelfDefinedStructure named: 'STARTUPINFO')
> >       flags: StartfUsestdhandles;
> >        hStdOutput: hWritePipe;
> >   yourself

> > To read i do

> > buffer := String new: 100.
> > hReadPipe read: buffer size into: buffer



Sun, 10 Oct 2004 14:26:54 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Input/output redirecting

2. Redirecting input and output...

3. How to redirect input output

4. Redirecting input and output..

5. How to redirect the standard output to a REXX-variable

6. Ada binding to redirect standard output in Win32

7. redirecting the standard output

8. redirecting standard output from a dll

9. REDIRECT Standard Output

10. How To Redirect Standard Output To A Text Widget

11. redirecting standard output

12. standard input and output question

 

 
Powered by phpBB® Forum Software