fork/exec ShellExecute

F

Fitzgerald,Greg

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

Shashank Date

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

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
 
J

Joel VanderWerf

Fitzgerald said:
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
 
S

Shashank Date

--- Joel VanderWerf said:
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
 

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,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top