(* Collection of code snippets by Arne Vajhøj *)
(* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) *)
program executor;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  ShellApi,
  Windows,
  IdTCPServer,
  IdContext,
  IdGlobal;

type
  THandler = class
    public
      procedure Exec(AContext : TIdContext);
  end;

procedure THandler.Exec(AContext : TIdContext);

var
  cmd : string;

begin
  if AContext.Connection.Socket.Readable then begin
    cmd := AContext.Connection.IOHandler.ReadLn;
    ShellExecute(0, 'open', PChar(cmd), nil, nil, SW_SHOWNORMAL) ;
  end;
end;

var
  srv : TIdTCPServer;
  h : THandler;

begin
  srv := TIdTCPServer.Create;
  h := THandler.Create;
  with srv.Bindings.Add do begin
    IP := '127.0.0.1';
    Port := 1234;
  end;
  srv.OnExecute := h.Exec;
  srv.Active := true;
  readln;
  h.Destroy;
  srv.Destroy;
end.
