fork/exec ShellExecute

Discussion in 'Ruby' started by Fitzgerald,Greg, Aug 16, 2004.

  1. I am trying to launch a Windoze application and then wait for the app to
    close before continuing. If I were on a Unix variant I'd do this:

    fork { exec("myApp") }
    Process.wait

    But unfortunately, fork is not implemented for Ruby on Windows. A DOS
    limitation I assume?

    Using the raw Win32 API, I can do this (in C):

    SHELLEXECUTEINFO ShExecInfo = {0};
    ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
    ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
    ShExecInfo.hwnd = NULL;
    ShExecInfo.lpVerb = NULL;
    ShExecInfo.lpFile = "myApp.exe";
    ShExecInfo.lpParameters = "";
    ShExecInfo.lpDirectory = NULL;
    ShExecInfo.nShow = NULL;
    ShExecInfo.hInstApp = NULL;
    ShellExecuteEx( &ShExecInfo );
    WaitForSingleObject( ShExecInfo );

    Is there a way on Windows that I can wait for the app to close that's as
    elegant as the Unix way? I only need it to work on Windows but just out
    of curiosity, is there a platform independent way?

    Thanks,
    Greg

    P.S. I apologize for the message at the bottom here. It automatically
    gets tacked onto the end of all outgoing mail, and I just love getting
    Ruby email at work.

    CONFIDENTIALITY NOTICE

    This message and any included attachments
    are from Cerner Corporation and are intended
    only for the addressee. The information
    contained in this message is confidential and
    may constitute inside or non-public information
    under international, federal, or state
    securities laws. Unauthorized forwarding,
    printing, copying, distribution, or use of such
    information is strictly prohibited and may be
    unlawful. If you are not the addressee, please
    promptly delete this message and notify the
    sender of the delivery error by e-mail or you
    may call Cerner's corporate offices in Kansas
    City, Missouri, U.S.A at (+1) (816)221-1024.
    ---------------------------------------- --
     
    Fitzgerald,Greg, Aug 16, 2004
    #1
    1. Advertising

  2. Hi Greg,

    > Is there a way on Windows that I can wait for the
    > app to close that's as
    > elegant as the Unix way?


    Have you looked at win32-process on rubyforge?
    http://rubyforge.org/projects/win32utils/

    Let us know if it does not work in your case.

    > Thanks,
    > Greg


    <snip>

    > may call Cerner's corporate offices in Kansas
    > City, Missouri, U.S.A at (+1) (816)221-1024.
    > ---------------------------------------- --


    Do you know that there is Ruby User's Group in
    Overland Park? Currently there are 3.5 members ;-)

    Contact me if you are interested in joining.
    -- shanko






    _______________________________
    Do you Yahoo!?
    Express yourself with Y! Messenger! Free. Download now.
    http://messenger.yahoo.com
     
    Shashank Date, Aug 16, 2004
    #2
    1. Advertising

  3. Fitzgerald,Greg wrote:
    > I am trying to launch a Windoze application and then wait for the app to
    > close before continuing. If I were on a Unix variant I'd do this:
    >
    > fork { exec("myApp") }
    > Process.wait


    This will wait for myApp to close:

    system("myApp")

    Other ruby threads will keep running. If you want the main ruby thread
    to keep running, too, just do this:

    th = Thread.new do
    system("myApp")
    end

    # do some stuff

    th.join # wait for myApp to close

    # then do something else
     
    Joel VanderWerf, Aug 16, 2004
    #3
  4. --- Joel VanderWerf <> wrote:

    > This will wait for myApp to close:
    >
    > system("myApp")


    And if you want to capture stdout you can also do
    back-quoting:

    output = `myapp`

    or

    output = %x{myapp}


    wherever there is system("myapp")

    > Other ruby threads will keep running. If you want
    > the main ruby thread
    > to keep running, too, just do this:
    >
    > th = Thread.new do
    > system("myApp")
    > end
    >
    > # do some stuff
    >
    > th.join # wait for myApp to close
    >
    > # then do something else
    >
    >





    __________________________________
    Do you Yahoo!?
    Yahoo! Mail - 50x more storage than other providers!
    http://promotions.yahoo.com/new_mail
     
    Shashank Date, Aug 16, 2004
    #4
    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,578
    Tony Edgecombe
    Jan 9, 2004
  2. Guest

    ShellExecute and Process

    Guest, Nov 3, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    572
  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,938
    Kevin Spencer
    Oct 1, 2004
  4. John

    ShellExecute Question

    John, Dec 7, 2004, in forum: C++
    Replies:
    3
    Views:
    9,008
    James Rafter
    Dec 7, 2004
  5. Eric Snow

    os.fork and pty.fork

    Eric Snow, Jan 8, 2009, in forum: Python
    Replies:
    0
    Views:
    575
    Eric Snow
    Jan 8, 2009
Loading...

Share This Page