Delphi Console Application - WeOnlyDo Discussion board

Delphi Console Application (General questions)

by John, Wednesday, February 04, 2009, 05:36 (5771 days ago)

Hello Kreso,

I'm having difficulty connecting with a console application. I don't think it's because I'm not trapping any events. Is these something else that has to happen in a console app to trigger connect?

code follows (compiles and executes with no issues):

program console;

{$APPTYPE CONSOLE}

uses
SysUtils, Variants, Classes, OleCtrls, WODSSHLib_TLB, WODSSHKeyLib_TLB, OleServer, ActiveX;

var

wodSSH1: TwodSSH;
Keys1: TKeys;
bExec: Boolean;



begin
{ TODO -oUser -cConsole Main : Insert code here }

CoInitialize(nil);
bExec := False;
wodSSH1 := TwodSSH.Create(nil);
Keys1 := TKeys.Create(nil);
wodSSH1.Hostname := '192.168.49.355';
wodSSH1.Login := 'testaccount';
wodSSH1.Password := 'testpass';
wodSSH1.Authentication := authPassword;
wodSSH1.Protocol := SSH2;
wodSSH1.Port := 22;
WodSSH1.AllocatePty := True;
WodSSH1.Encryption := encAny;
WodSSH1.ShowStdErrorMessages := True;

wodSSH1.PrivateKey := keys1.PrivateKey[RSAkey];
WriteLn('Attempting to connect');
wodSSH1.Connect;
wodSSH1.Blocking := True;
wodSSH1.DataReady := 0;
sleep(1000);
WodSSH1.Disconnect;
CoUninitialize;
end.

Re: Delphi Console Application

by wodDamir, Wednesday, February 04, 2009, 08:18 (5771 days ago) @ John

Hi John,

Can you please move the line that you set Blocking moder in before calling connect?

I believe this should resolve the problem that you have.

Regards,
Damba

Re: Delphi Console Application

by John, Tuesday, February 10, 2009, 00:45 (5765 days ago) @ wodDamir

Hi John,

Can you please move the line that you set Blocking moder in before calling connect?

I believe this should resolve the problem that you have.

Regards,
Damba

Thanks for your help on that, it fixed the problem. Now I have a followup question...

How do I access the receive event to catch output coming back from the server? This is a console app so I can't just write a procedure and edit the object. I'm sure you guys have a way to do this, I just don't know what it is.

Re: Delphi Console Application

by wodDamir, Tuesday, February 10, 2009, 10:30 (5765 days ago) @ John

Hi John,

I honestly don't know how to declare events in Delphi (we're not Delphi guru's), but I don't see the point to this, since you shouldn't use Events in Blocking mode anyway.

Instead, I would suggest that you use Receive method to receive the incoming response and loop it while DataReady is bigger then 0.

Can you try that instead?

regards,
Damba