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

Discussion in 'C Programming' started by Ben, Aug 29, 2009.

  1. Ben

    Ben Guest

    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.
    Ben, Aug 29, 2009
    #1
    1. Advertising

  2. Ben

    Flash Gordon Guest

    Re: How to pass stdin of a C++ program to the stdin of a processcreated with ShellExecute()

    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
    Flash Gordon, Aug 29, 2009
    #2
    1. Advertising

  3. Ben

    jacob navia Guest

    Re: How to pass stdin of a C++ program to the stdin of a processcreated with ShellExecute()

    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
    jacob navia, Aug 29, 2009
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marcel Sammut

    Using ShellExecute PrintTo

    Marcel Sammut, Jan 3, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    4,563
    Tony Edgecombe
    Jan 9, 2004
  2. Guest

    ShellExecute and Process

    Guest, Nov 3, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    567
  3. =?Utf-8?B?RGF2aWRT?=

    ShellExecute command for ASP.NET?

    =?Utf-8?B?RGF2aWRT?=, Sep 30, 2004, in forum: ASP .Net
    Replies:
    12
    Views:
    6,910
    Kevin Spencer
    Oct 1, 2004
  4. John

    ShellExecute Question

    John, Dec 7, 2004, in forum: C++
    Replies:
    3
    Views:
    8,997
    James Rafter
    Dec 7, 2004
  5. Josh

    Win32api shellexecute Bshow

    Josh, Feb 16, 2005, in forum: Python
    Replies:
    2
    Views:
    1,887
Loading...

Share This Page