-
Re: Re: How to (Shell)Execute a program modally?
"Ralph D. Cole" <nt_consulting32@SPAMhotmail.com> wrote:
>
>"Arnab Bose" <hirak_99@yahoo.com> wrote:
>>
>>I am creating something like a frontend for an archiver. The archiver supports
>>a 32bit-console command line interface. How do I run it (to extract a file)
>>and *wait* till it completes? (Also, out of curiosity, is it possible to
>>get hold of the text that it generates?)
>
>[Warning air code follows!]
>
>The simplest way is to use CreateProcess()
>
> CreateProcess( NULL, "Archive.exe > unique_fileName.txt", blah, blah...)
> (Maybe using WaitForInputIdle )
>
>Then set up a wait for FolderChange() looking for your unique file name.
>When you get a chance open the file and read the contents.
>
>Note: You can also do something like...
> CreateProcess( NULL, "start \"My Archive\" /MIN Archive.exe > file",
>...
>to control the console window.
>
>
>-ralph
>
Thanks a lot!
However, I will appreciate some more details on "set up a wait for FolderChange()".
Are you talking about a hook?
Actually, I thought there would be a better solution that to monitor the
creation of the file - don't you think so? This seems to be somewhat adhoc.
There must be some other way to execute something till it completes (like
"start /w ..." works from command prompt), but I just can't find it in the
overbloated SDK!
Thanks again.
- Arnab.
-
Re: Re: How to (Shell)Execute a program modally?
"Arnab Bose" <hirak_99@yahoo.com> wrote:
>
>"Ralph D. Cole" <nt_consulting32@SPAMhotmail.com> wrote:
>>
>>"Arnab Bose" <hirak_99@yahoo.com> wrote:
>>>
>>>I am creating something like a frontend for an archiver. The archiver
supports
>>>a 32bit-console command line interface. How do I run it (to extract a
file)
>>>and *wait* till it completes? (Also, out of curiosity, is it possible
to
>>>get hold of the text that it generates?)
>>
>>[Warning air code follows!]
>>
>>The simplest way is to use CreateProcess()
>>
>> CreateProcess( NULL, "Archive.exe > unique_fileName.txt", blah, blah...)
>> (Maybe using WaitForInputIdle )
>>
>>Then set up a wait for FolderChange() looking for your unique file name.
>>When you get a chance open the file and read the contents.
>>
>>Note: You can also do something like...
>> CreateProcess( NULL, "start \"My Archive\" /MIN Archive.exe > file",
>>...
>>to control the console window.
>>
>>
>>-ralph
>>
>
>Thanks a lot!
>However, I will appreciate some more details on "set up a wait for FolderChange()".
>Are you talking about a hook?
>Actually, I thought there would be a better solution that to monitor the
>creation of the file - don't you think so? This seems to be somewhat adhoc.
>There must be some other way to execute something till it completes (like
>"start /w ..." works from command prompt), but I just can't find it in the
>overbloated SDK!
>
>Thanks again.
>- Arnab.
Yes there are other ways. I am sure someone will respond here with additional
solutions and I have included one below. For example, you can capture the
PID of the launched process then go seek and find out when it dies. You can
capture the window title, and enum through a list of open windows till it
disappears, hooks, etc.
All of which attempt some sort of synchronous control which IMHO is a purely
asynchronous task. It locks both process's lifecycles together. By simply
launching a process and letting it or the O/S tell you when it is done is
a very manageable and scaleable solution.
What if, for example, you later decide you need to run Archive on a remote
machine? What about latency time gaps? What if the base application dies
before Archive finishes? etc. What if Archive dies?
I like the simpler life. To paraphase David Platt - "Let Go, Let COM+" -
"Let Go - Let Windows".
I did a quick web search, here is my meager list... I am sure you can find
more.
This example shows catching File events: (MFC)
<http://www.codeguru.com/files/FileWatch.html>
This shows the typical 'synchronous' method:
<http://www.codeguru.com/system/runProcess.html>
-
Re: Re: How to (Shell)Execute a program modally?
"Ralph D. Cole" <nt_consulting32@SPAMhotmail.com> wrote:
>
>"Arnab Bose" <hirak_99@yahoo.com> wrote:
>>
>>Thanks a lot!
>>However, I will appreciate some more details on "set up a wait for FolderChange()".
>>Are you talking about a hook?
>>Actually, I thought there would be a better solution that to monitor the
>>creation of the file - don't you think so? This seems to be somewhat adhoc.
>>There must be some other way to execute something till it completes (like
>>"start /w ..." works from command prompt), but I just can't find it in
the
>>overbloated SDK!
>>
>>Thanks again.
>>- Arnab.
>
>Yes there are other ways. I am sure someone will respond here with additional
>solutions and I have included one below. For example, you can capture the
>PID of the launched process then go seek and find out when it dies. You
can
>capture the window title, and enum through a list of open windows till it
>disappears, hooks, etc.
>
>All of which attempt some sort of synchronous control which IMHO is a purely
>asynchronous task. It locks both process's lifecycles together. By simply
>launching a process and letting it or the O/S tell you when it is done is
>a very manageable and scaleable solution.
>
>What if, for example, you later decide you need to run Archive on a remote
>machine? What about latency time gaps? What if the base application dies
>before Archive finishes? etc. What if Archive dies?
>
>I like the simpler life. To paraphase David Platt - "Let Go, Let COM+" -
>"Let Go - Let Windows".
>
>I did a quick web search, here is my meager list... I am sure you can find
>more.
>
>This example shows catching File events: (MFC)
><http://www.codeguru.com/files/FileWatch.html>
>
>This shows the typical 'synchronous' method:
><http://www.codeguru.com/system/runProcess.html>
>
Thanks a lot for taking interest and posting solutions, Ralph! The CodeGURU
links you supplied are great! I did not know of that site before, and now
I see what I've been missing out!
I've also found some code snippet myself:
Public Sub ExecuteAndWait(cmdline As String)
Dim NameOfProc As PROCESS_INFORMATION
Dim NameStart As STARTUPINFO
Dim X As Long
NameStart.cb = Len(NameStart)
X = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&,
0&, NameStart, NameOfProc)
X = WaitForSingleObject(NameOfProc.hProcess, INFINITE)
X = CloseHandle(NameOfProc.hProcess)
End Sub
This is basically the same as the RunProcessAndWait() CodeGURU example. Guess
where it was hiding? In the MSDN! (Silly me!)
Thanks again, Ralph!
- Arnab
-
Re: Re: How to (Shell)Execute a program modally?
The most common way to do this is to launch the process with CreateProcess()
and then call WaitForSingleObject() using the PID given to you by CreateProcess.
(And after WaitForSingleObject returns, CloseHandle must be called using
the same PID)
I would think this is the simplest way to accomplish what you're talking
about...
Pat
"Arnab Bose" <hirak_99@yahoo.com> wrote:
>
>"Ralph D. Cole" <nt_consulting32@SPAMhotmail.com> wrote:
>>
>>"Arnab Bose" <hirak_99@yahoo.com> wrote:
>>>
>>>I am creating something like a frontend for an archiver. The archiver
supports
>>>a 32bit-console command line interface. How do I run it (to extract a
file)
>>>and *wait* till it completes? (Also, out of curiosity, is it possible
to
>>>get hold of the text that it generates?)
>>
>>[Warning air code follows!]
>>
>>The simplest way is to use CreateProcess()
>>
>> CreateProcess( NULL, "Archive.exe > unique_fileName.txt", blah, blah...)
>> (Maybe using WaitForInputIdle )
>>
>>Then set up a wait for FolderChange() looking for your unique file name.
>>When you get a chance open the file and read the contents.
>>
>>Note: You can also do something like...
>> CreateProcess( NULL, "start \"My Archive\" /MIN Archive.exe > file",
>>...
>>to control the console window.
>>
>>
>>-ralph
>>
>
>Thanks a lot!
>However, I will appreciate some more details on "set up a wait for FolderChange()".
>Are you talking about a hook?
>Actually, I thought there would be a better solution that to monitor the
>creation of the file - don't you think so? This seems to be somewhat adhoc.
>There must be some other way to execute something till it completes (like
>"start /w ..." works from command prompt), but I just can't find it in the
>overbloated SDK!
>
>Thanks again.
>- Arnab.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks