BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Create Process question

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> comp.lang.pascal.delphi.misc
View previous topic :: View next topic  
Author Message
Andy
Guest





PostPosted: Sat Nov 22, 2003 6:09 pm    Post subject: Create Process question Reply with quote



Greetings:

I realise much of this is over my head at this point, but I'm trying.
I'm using the code below to run a DOS application, however, I don't understand how to do two things.

How do I make sure the DOS program terminates? I currently run a PIF file with the "Close on Exit"
checked. I was wondering if I can avoid this.

Secondly, in ShellExecute I can specify SW_HIDE, but I can't seem to figure it out how to apply that
option in the code below.

procedure TfrmMain.Compile;
begin
Try
{ShellExecute(Handle, 'Open',pchar('DosApp.exe'), 'Text.old', nil, SW_Hide);} // Old Way
ProgramRunWait('DosApp.pif Text.old',extractfilepath(application.exename),True);
CopyFile('Text.old', 'Text.new')
Except
Showmessage('Compiler Error!');
end;
end;

procedure TfrmMain.ProgramRunWait (const CommandLine, DefaultDirectory: string; Wait: boolean);
var
StartUpInfo: TStartUpInfo;
ProcInfo: Process_Information;
Dir, Msg: PChar;
ErrNo: integer;
E: Exception;
begin
FillChar(StartUpInfo, SizeOf(StartUpInfo), 0);
StartUpInfo.cb := SizeOf(StartUpInfo);
if DefaultDirectory <> '' then
Dir := PChar(DefaultDirectory)
else
Dir := nil;
if CreateProcess(nil, PChar(CommandLine), nil, nil, False,
0, nil, Dir, StartUpInfo, ProcInfo) then
begin
try
if Wait then
WaitForSingleObject(ProcInfo.hProcess, INFINITE);
finally
CloseHandle(ProcInfo.hThread);
CloseHandle(ProcInfo.hProcess);
end;
end
else
begin
ErrNo := GetLastError;
Msg := AllocMem(4096);
try
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, nil, ErrNo,
0, Msg, 4096, nil);
E := Exception.Create('Create Process Error #'
+ IntToStr(ErrNo) + ': '
+ string(Msg));
finally
FreeMem(Msg);
end;
raise e;
end;
end;

TIA


Andy
The Perpetual Novice Programmer
Back to top
Maarten Wiltink
Guest





PostPosted: Sat Nov 22, 2003 7:39 pm    Post subject: Re: Create Process question Reply with quote



"Andy" <ptrails (AT) NoFlyersThankYou (DOT) rogers.com> wrote


Quote:
How do I make sure the DOS program terminates?

Theoretical computer scientists have wondered about this.
Current concensus is that one doesn't know in general.


Quote:
[...] in ShellExecute I can specify SW_HIDE, but I can't seem to
figure it out how to apply that option in the code below.

You're using CreateProcess. Type "CreateProcess", press F1, read help.
Pay particular attention to the "STARTUPINFO" bit; this seems to me
the most logical place to place that particular bit of information.
(And yes, I checked, too. (Whatever happened to basic problemsolving?))

Groetjes,
Maarten Wiltink



Back to top
Andy
Guest





PostPosted: Sat Nov 22, 2003 8:29 pm    Post subject: Re: Create Process question Reply with quote



On Sat, 22 Nov 2003 20:39:58 +0100, "Maarten Wiltink" <maarten (AT) kittensandcats (DOT) net> wrote:

Quote:
[...] in ShellExecute I can specify SW_HIDE, but I can't seem to
figure it out how to apply that option in the code below.

You're using CreateProcess. Type "CreateProcess", press F1, read help.
Pay particular attention to the "STARTUPINFO" bit; this seems to me
the most logical place to place that particular bit of information.
(And yes, I checked, too. (Whatever happened to basic problemsolving?))

What I had tried before was....

begin
FillChar(StartUpInfo, SizeOf(StartUpInfo), 0);
StartUpInfo.cb := SizeOf(StartUpInfo);
StartUpInfo.wShowWindow := SW_HIDE;
// and so on

However, this didn't work. Your process of shaming me forced me to reread it which resulted in...

begin
FillChar(StartUpInfo, SizeOf(StartUpInfo), 0);
StartUpInfo.dwFlags := STARTF_USESHOWWINDOW;
StartUpInfo.cb := SizeOf(StartUpInfo);
StartUpInfo.wShowWindow := SW_HIDE;
// and so on

Sorry about that.






Andy
The Perpetual Novice Programmer

Back to top
Maarten Wiltink
Guest





PostPosted: Sat Nov 22, 2003 10:23 pm    Post subject: Re: Create Process question Reply with quote

"Andy" <ptrails (AT) NoFlyersThankYou (DOT) rogers.com> wrote

Quote:
On Sat, 22 Nov 2003 20:39:58 +0100, "Maarten Wiltink"
[email]maarten (AT) kittensandcats (DOT) net[/email]> wrote:


Quote:
"Aaarrgh!"

"Type <appropriate>, press F1, read help."

[...] Your process of shaming me forced me to reread it which
resulted in...

begin
FillChar(StartUpInfo, SizeOf(StartUpInfo), 0);
StartUpInfo.dwFlags := STARTF_USESHOWWINDOW;

Yup, that's the bit that you missed (at first) alright.


Quote:
StartUpInfo.cb := SizeOf(StartUpInfo);
StartUpInfo.wShowWindow := SW_HIDE;
// and so on

Sorry about that.

Believe it or not, even on my rather cursory reading of the help page
involved, I had spotted that seemingly-unrelated flag just north of
where everybody was bound to look. That's not talent; that's practice.
Endless practice doing what I tell other people every chance I get:
type the word, press F1, read help.

I'm pleased you found the solution. I hope you're not offended by my
advice. I hope it'll stand you in good stead, and next time you'll
be able to find the solution that much quicker.

Groetjes,
Maarten Wiltink



Back to top
Jeremy Collins
Guest





PostPosted: Sun Nov 23, 2003 11:04 am    Post subject: Re: Create Process question Reply with quote

Andy wrote:


Quote:
{ShellExecute(Handle, 'Open',pchar('DosApp.exe'), 'Text.old', nil, SW_Hide);} // Old Way
ProgramRunWait('DosApp.pif Text.old',extractfilepath(application.exename),True);
CopyFile('Text.old', 'Text.new')
Except
Showmessage('Compiler Error!');

Why are you blaming the compiler when this fails?

--
jc

Remove the -not from email


Back to top
Andy
Guest





PostPosted: Sun Nov 23, 2003 1:21 pm    Post subject: Re: Create Process question Reply with quote

On Sun, 23 Nov 2003 11:04:44 +0000, Jeremy Collins <jd.collins (AT) ntlworld-not (DOT) com> wrote:

Quote:
Andy wrote:
Showmessage('Compiler Error!');

Why are you blaming the compiler when this fails?

I'm not blaming the Delphi compiler. The DosApp in question is a resource compiler.


Andy
The Perpetual Novice Programmer

Back to top
Andy
Guest





PostPosted: Sun Nov 23, 2003 1:29 pm    Post subject: Re: Create Process question Reply with quote

On Sat, 22 Nov 2003 23:23:36 +0100, "Maarten Wiltink" <maarten (AT) kittensandcats (DOT) net> wrote:

Quote:
[...] Your process of shaming me forced me to reread it which
resulted in...
StartUpInfo.dwFlags := STARTF_USESHOWWINDOW;
Yup, that's the bit that you missed (at first) alright.

I'm pleased you found the solution. I hope you're not offended by my
advice. I hope it'll stand you in good stead, and next time you'll
be able to find the solution that much quicker.

You're pleased! I'm elated! BTW, none taken. I am fully aware of your style. While it may sound
harsh, I realized that you knew the info was there, so I looked again (and harder). You surmised
correctly that I flew over that section and went straight to where the "SW_HIDE" reference was made.

Andy
The Perpetual Novice Programmer

Back to top
Jeremy Collins
Guest





PostPosted: Sun Nov 23, 2003 1:50 pm    Post subject: Re: Create Process question Reply with quote

Andy wrote:
Quote:
On Sun, 23 Nov 2003 11:04:44 +0000, Jeremy Collins <jd.collins (AT) ntlworld-not (DOT) com> wrote:


Andy wrote:

Showmessage('Compiler Error!');

Why are you blaming the compiler when this fails?


I'm not blaming the Delphi compiler. The DosApp in question is a resource compiler.

Isn't it more likely to return an error code than cause an exception?

--
jc

Remove the -not from email


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> comp.lang.pascal.delphi.misc All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.