Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Console app parent 1

Status
Not open for further replies.

goodmanrAy

Programmer
Feb 6, 2002
53
0
0
GB
Hello

Does anyone know if/how I can set the parent of a console app.

I run a console from another exe and I want the console to finish when the main app closes.

Any ideas

Andrew
 
Sorry
I made a mistake

Does anyone know how I can get the handle of a console app from within the console app.

Like self.handle in a form.

Thanks

Andrew
 
I'm not sure exactly what you're wanting to do...

GetStdHandle in the Windows unit will get handles for the console, but the question is that I don't think it'll get what you seem to be looking for by your first post.

From the help:
Code:
function GetStdHandle(nStdHandle: DWord): THandle;

STD_INPUT_HANDLE	Standard input handle
STD_OUTPUT_HANDLE	Standard output handle
STD_ERROR_HANDLE	Standard error handle

These are for reading and writing to the console.

So what are you looking for, precisely?
 
thanks for your reply

I think I'm a litle confused!

I'm running a console app (2) from another console app (1).

I'm using ShellExecute, and I want the parent of console app (2) to be console app (1)

I don't know how to get the handle of a console app.


thanks

Andrew
 
Okay so you're wanting console app #2 to be controlled by console app #1? In the sense that app #1 terminates, console app #2 terminates as well?
 
Okay, I don't think you can do it with ShellExecute, since you need a process handle to the app you're calling returned. ShellExecuteEx should be possible, though, since I see a process handle being returned...

The way I prefer, though.
Code:
{$APPTYPE CONSOLE}
program spawnapp; uses dialogs, messages, windows;
  { app that spawns an app that runs endlessly and then     forcibly terminates it after five seconds.}
const
  ProgramName: string = 'SPAWNEDAPP.EXE';
  CommandParm: string = ' ';
var
  StartInfo  : TStartupInfo;
  ProcInfo   : TProcessInformation;
  CreateOK   : Boolean;
begin
  writeln('Spawning app.');
  readln;
  FillChar(StartInfo,SizeOf(TStartupInfo),#0);
  FillChar(ProcInfo,SizeOf(TProcessInformation),#0);
  StartInfo.cb := SizeOf(TStartupInfo);
  CreateOK := Windows.CreateProcess(nil,
              PChar(ProgramName + ' ' + CommandParm),
              nil, nil, False,
              CREATE_NEW_PROCESS_GROUP+NORMAL_PRIORITY_CLASS,
              nil, nil, StartInfo, ProcInfo);
  if not CreateOK then
    MessageDlg('Could not run process.', mtError, [mbOK], 0);
  windows.sleep(5000);
  TerminateProcess(ProcInfo.hProcess, 0);
  CloseHandle(ProcInfo.hProcess);
end.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top