 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Tom Backer Johnsen Guest
|
Posted: Fri Jun 02, 2006 8:15 am Post subject: Using ShellExecute |
|
|
I am using ShellExecute to start a batch program, where the call on
the program contains filenames for the input (a set of commands) and
the output file. After the call, I want to process the output file.
Evidently, my program (written in D7) goes on with its own operations
without waiting for anything, with the result that the output file is
empty right after the call on ShellExecute. The operations in the
batch program may vary in respect to time, sometimes quite lengthy
(actually, it is a statistical system called R, very nice).
Now, is there some way of checking if the batch program is finished so
I can delay my program until the batch program is finished? Some API
call using the handle perhaps?
Tom |
|
| Back to top |
|
 |
Pete Fraser Guest
|
Posted: Fri Jun 02, 2006 9:15 am Post subject: Re: Using ShellExecute |
|
|
"Tom Backer Johnsen" <backer (AT) psych (DOT) uib.no> wrote in message
news:447fef7b (AT) newsgroups (DOT) borland.com...
| Quote: | I am using ShellExecute to start a batch program, where the call on the
program contains filenames for the input (a set of commands) and the output
file. After the call, I want to process the output file. Evidently, my
program (written in D7) goes on with its own operations without waiting for
anything, with the result that the output file is empty right after the
call on ShellExecute. The operations in the batch program may vary in
respect to time, sometimes quite lengthy (actually, it is a statistical
system called R, very nice).
Now, is there some way of checking if the batch program is finished so I
can delay my program until the batch program is finished? Some API call
using the handle perhaps?
|
This is the C++ way of doing it - you may be able to work out the Delphi way
from this...
SHELLEXECUTEINFO ExecInfo;
memset (&ExecInfo, 0, sizeof(ExecInfo));
ExecInfo.cbSize = sizeof(ExecInfo);
ExecInfo.lpVerb = "open";
ExecInfo.lpFile = AppPath.c_str();
ExecInfo.lpParameters = Cmdline.c_str();
ExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ExecInfo.nShow = SW_SHOW;
bool RetCode = ShellExecuteEx(&ExecInfo);
WaitForSingleObject(ExecInfo.hProcess, INFINITE); // this waits
--
HTH Pete
=================================
www.frasersoft.net
GenHelp: "Making writing help fun" |
|
| Back to top |
|
 |
Tom Backer Johnsen Guest
|
Posted: Fri Jun 02, 2006 10:15 am Post subject: Re: Using ShellExecute |
|
|
Pete Fraser wrote:
| Quote: | "Tom Backer Johnsen" <backer (AT) psych (DOT) uib.no> wrote in message
news:447fef7b (AT) newsgroups (DOT) borland.com...
I am using ShellExecute to start a batch program, where the call on the
program contains filenames for the input (a set of commands) and the output
file. After the call, I want to process the output file. Evidently, my
program (written in D7) goes on with its own operations without waiting for
anything, with the result that the output file is empty right after the
call on ShellExecute. The operations in the batch program may vary in
respect to time, sometimes quite lengthy (actually, it is a statistical
system called R, very nice).
|
Thanks for the tip. With the example I found the corresponding Object
Pascal code on the net:
http://www.latiumsoftware.com/en/pascal/delphi-1.php
(Towards the end) Now, the next step is to get it working.
Tom |
|
| Back to top |
|
 |
Tom Backer Johnsen Guest
|
Posted: Fri Jun 02, 2006 11:15 am Post subject: Re: Using ShellExecute |
|
|
Tom Backer Johnsen wrote:
....
Yes, it works. However, since the batch program is a DOS type
program, a command prompt window flashes up while it is working, which
I really do not like. With ShellExecute I could at least hide it by
setting the last argument to zero.
How do I manage that with CreateProcess?
Tom |
|
| Back to top |
|
 |
Jesper Hogstrom (Borland) Guest
|
Posted: Fri Jun 02, 2006 1:15 pm Post subject: Re: Using ShellExecute |
|
|
Tom Backer Johnsen wrote:
| Quote: | With ShellExecute I could at least hide it by setting the
last argument to zero.
How do I manage that with CreateProcess?
|
Iirc you change the value in nShow:
ExecInfo.nShow = SW_SHOW;
to something different. Try 0. Or google for the correct define. Or grep
the rtl code for SW_SHOW and see what constant in the 'hood makes most
sense.
--Jesper |
|
| Back to top |
|
 |
Tom Backer Johnsen Guest
|
Posted: Fri Jun 02, 2006 1:16 pm Post subject: Re: Using ShellExecute |
|
|
Jesper Hogstrom (Borland) wrote:
| Quote: | Tom Backer Johnsen wrote:
With ShellExecute I could at least hide it by setting the last
argument to zero.
How do I manage that with CreateProcess?
Iirc you change the value in nShow:
ExecInfo.nShow = SW_SHOW;
to something different. Try 0. Or google for the correct define. Or grep
the rtl code for SW_SHOW and see what constant in the 'hood makes most
sense.
|
Thanks. I thought I had done just that, looking at the various
attributes og things. But a Google search turned up:
Startinfo.dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;
Startinfo.wShowWindow := SW_HIDE;
I had tried changing wShowWindow with no effect. Adding the other
line did the trick. Why, I do not know. But it works.
Tom
|
|
| Back to top |
|
 |
K. Sallee Guest
|
|
| Back to top |
|
 |
Tom Backer Johnsen Guest
|
Posted: Sat Jun 03, 2006 8:11 am Post subject: Re: Using ShellExecute |
|
|
K. Sallee wrote:
....
| Quote: | http://www.mail-archive.com/r-devel@r-project.org/msg03691.html
|
That was a really "nice to know" thing. Thanks!
Tom |
|
| Back to top |
|
 |
Tom Backer Johnsen Guest
|
Posted: Sat Jun 03, 2006 8:11 am Post subject: Re: Using ShellExecute |
|
|
K. Sallee wrote:
| Quote: |
(actually, it is a statistical system called R, very nice).
I have not tried it myself, or know if it is still being developed, but
there is a DCOM R server you might try to access R more directly:
http://cran.r-project.org/contrib/extra/dcom/RSrv135.html
This is not what you need, but if you ever wish to you can now write an
R extension using Delphi :
|
That is correct, what I want to do at the moment is to use R to
analyse data I have around in other formats and somewhat odd data
structures with my own programs in control. So what I do is simply to
write the data to a text file, write the necessary commands to
another, start the batch version of R and collect the output.
As a result, all the results (from both R and non-R functions) are
kept together and can be reproduced any any time, with variations.
That is the objective.
So, writing extensions is not of primary concern at the moment.
However, making a "package" would be useful, but that is a different
matter altogether.
|
|
| Back to top |
|
 |
Tom Backer Johnsen Guest
|
Posted: Sat Jun 03, 2006 8:11 am Post subject: Re: Using ShellExecute |
|
|
Marc Rohloff [TeamB] wrote:
| Quote: | On Fri, 02 Jun 2006 11:31:59 +0200, Tom Backer Johnsen wrote:
http://www.latiumsoftware.com/en/pascal/delphi-1.php
(Towards the end) Now, the next step is to get it working.
You may want to look at the StartupInfo. There are members which let
you read the standard output directly without using a temporary file.
|
Thanks for the tip.
Tom |
|
| Back to top |
|
 |
Chris Burrows Guest
|
Posted: Sat Jun 03, 2006 8:11 am Post subject: Re: Using ShellExecute |
|
|
"Tom Backer Johnsen" <backer (AT) psych (DOT) uib.no> wrote in message
news:44811e53 (AT) newsgroups (DOT) borland.com...
| Quote: | Marc Rohloff [TeamB] wrote:
On Fri, 02 Jun 2006 11:31:59 +0200, Tom Backer Johnsen wrote:
http://www.latiumsoftware.com/en/pascal/delphi-1.php
(Towards the end) Now, the next step is to get it working.
You may want to look at the StartupInfo. There are members which let
you read the standard output directly without using a temporary file.
Thanks for the tip.
|
There's an example of how to to this at:
http://delphi.about.com/cs/adptips2001/a/bltip0201_2.htm
It also shows you how you can periodically call ProcessMessages while
waiting for confirmation that your program has finished .e.g check every
100ms:
repeat
Apprunning := WaitForSingleObject (ProcessInfo.hProcess,100) ;
Application.ProcessMessages;
until (Apprunning <> WAIT_TIMEOUT) ;
--
Chris Burrows
CFB Software
http://www.cfbsoftware.com/gpcp |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|