Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > How to pass stdin of a C++ program to the stdin of a process createdwith ShellExecute()

Reply
Thread Tools

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

 
 
Ben
Guest
Posts: n/a
 
      08-29-2009
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.
 
Reply With Quote
 
 
 
 
Flash Gordon
Guest
Posts: n/a
 
      08-29-2009
Ben wrote:

<snip>

> 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.
--
Flash Gordon
 
Reply With Quote
 
 
 
 
jacob navia
Guest
Posts: n/a
 
      08-29-2009
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/p...32/index.shtml

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
peek at stdin, flush stdin Johnathan Doe C Programming 5 05-17-2013 04:30 PM
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Win32/Process when create a process, how to pass data Qi Lu Ruby 0 07-14-2008 07:38 PM
Reading from stdin then launching a program that reads from stdin strange behaviour Stefano Sabatini Perl Misc 6 07-29-2007 10:38 PM
Reading stdin once confuses second stdin read Charlie Zender C Programming 6 06-21-2004 01:39 PM



Advertisments