Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > fork/exec ShellExecute

Reply
Thread Tools

fork/exec ShellExecute

 
 
Fitzgerald,Greg
Guest
Posts: n/a
 
      08-16-2004

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.
---------------------------------------- --



 
Reply With Quote
 
 
 
 
Shashank Date
Guest
Posts: n/a
 
      08-16-2004
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


 
Reply With Quote
 
 
 
 
Joel VanderWerf
Guest
Posts: n/a
 
      08-16-2004
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


 
Reply With Quote
 
Shashank Date
Guest
Posts: n/a
 
      08-16-2004

--- Joel VanderWerf <(E-Mail Removed)> 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


 
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
Win32api shellexecute Bshow Josh Python 2 02-16-2005 07:14 PM
ShellExecute Question John C++ 3 12-07-2004 08:35 PM
ShellExecute command for ASP.NET? =?Utf-8?B?RGF2aWRT?= ASP .Net 12 10-01-2004 04:59 PM
Using ShellExecute PrintTo Marcel Sammut ASP .Net 1 01-09-2004 12:01 PM
ShellExecute and Process ASP .Net 1 11-03-2003 09:36 AM



Advertisments