How to pass stdin of a C++ program to the stdin of a process createdwith ShellExecute()

B

Ben

Hi, I've written a program (shex) that executes another program using
the
win32 ShellExecute() function, similar to what cygstart does for
cygwin (except without the argument length limit). For example, "shex
gvim" will start a new instance of gvim completely independently of
the parent shell.

An enhancement I would like to make is to be able to redirect the
stdin that my program (shex) receives to the stdin of the program
opened with ShellExecute(). This would enable me to do something like
"echo 'asdf' | shex gvim -", which would cause shex to take its stdin
('asdf') and redirect it to the new gvim process's stdin, which would
then be read by gvim into a new file (because of the '-' argument).

Obviously, I can read shex's stdin from within shex, but I have no
idea how to get a hold of the stdin of the spawned process from
ShellExecute() so I can write to it. Does anyone know how I can do
this? Also, it would be nice if I could simply perform some operations
on the stdin file descriptors themselves, rather than actually reading
and writing the stdin contents from my program, but I don't know how
to do that either. Any help is appreciated.
 
F

Flash Gordon

Ben wrote:

Obviously, I can read shex's stdin from within shex, but I have no
idea how to get a hold of the stdin of the spawned process from
ShellExecute() so I can write to it. Does anyone know how I can do
this? Also, it would be nice if I could simply perform some operations
on the stdin file descriptors themselves, rather than actually reading
and writing the stdin contents from my program, but I don't know how
to do that either. Any help is appreciated.

All this is highly Windows specific and not realy to do with the C
language at all (the issues would be the same in Delphi, for example, as
I know having used Delphi) so please drop comp.lang.c from follow-ups. I
don't know if it is appropriate for alt.comp.lang.learn.c-c++ since I
don't read that group.
 
J

jacob navia

Ben a écrit :
Hi, I've written a program (shex) that executes another program using
the
win32 ShellExecute() function, similar to what cygstart does for
cygwin (except without the argument length limit). For example, "shex
gvim" will start a new instance of gvim completely independently of
the parent shell.

An enhancement I would like to make is to be able to redirect the
stdin that my program (shex) receives to the stdin of the program
opened with ShellExecute(). This would enable me to do something like
"echo 'asdf' | shex gvim -", which would cause shex to take its stdin
('asdf') and redirect it to the new gvim process's stdin, which would
then be read by gvim into a new file (because of the '-' argument).

Obviously, I can read shex's stdin from within shex, but I have no
idea how to get a hold of the stdin of the spawned process from
ShellExecute() so I can write to it. Does anyone know how I can do
this? Also, it would be nice if I could simply perform some operations
on the stdin file descriptors themselves, rather than actually reading
and writing the stdin contents from my program, but I don't know how
to do that either. Any help is appreciated.

You have to open a pipe between the spawned process and the parent process.

I have written a tutorial for lcc-win, the compiler system. In this
tutorial I have a FAQ. Go to page 388 and see the question:

How do I spawn a process with redirected stdin and stdout?

The tutorial can be downloaded from

http://www.q-software-solutions.de/products/lcc-win32/index.shtml
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top