WaitFor fails while Prompt works (General questions)

by novanstar @, (6031 days ago)

Hi,
I am evaluating wodSSH for use in test automation. I am using Perl to request wodSSH COM object. My test code works if I specify Prompt before connection. But it would fail (got stuck) if I use WaitFor after connection instead. Can someone help me out? Thanks. (The target is Ubuntu Linux running sshd.)

==== code that WORKS ====
my $ssh = Win32::OLE->new( WeOnlyDo.wodSSHCom.1 );
$ssh->{Protocol} = 4;
$ssh->{HostName} = 'auto-dev03';
$ssh->{Blocking} = 'True';
$ssh->{Login} = 'autodev';
$ssh->{Prompt} = 'autodev@auto-dev03:~$ ';
$ssh->{Password} = 'password';
$ssh->Connect();
$ssh->Execute( ls
);
print $ssh->Receive();
print $ssh->Receive();
==========================

# if remove $ssh->{Prompt}... and use WaitFor instead, then it got
# stuck
$ssh->Connect();
$ssh->WaitFor('autodev@auto-dev03:~$ ');
$ssh->Execute( ls
, 'autodev@auto-dev03:~$ ');
print $ssh->Receive();
print $ssh->Receive();

locked

Re: WaitFor fails while Prompt works

by wodDamir @, (6031 days ago) @ novanstar

Hi,

First thing I noticed is that you use Receive method after the Execute. This would probably hang, since Execute already receives the string and removes it from the buffer. In that case Receive doesn't have anything to receive and causes a hang/timeout.

Since Execute has return type as String, you should better use something like this:

someStringVariable = ssh1.Execute( yourCommand\r\n , your_prompt );

The second thing I notices is that you are trying to execute a command without sending an Enter key. You should add \r\n after the command (as in my above statement).

Can you please try those suggestions? Does that work?

Regards,
Damba

locked

Re: WaitFor fails while Prompt works

by novanstar @, (6030 days ago) @ wodDamir

Thanks for your quick response and support. The return is my typo. The command is ls
. :P
I will try your suggestion. But what I still can't understand is why Prompt works even I issue Receive after Execute , and it did give me the print out of ls and if I run the script 3 times it may also print out result of ls command... .

Anyway, I will try your suggestion first. Thanks,

locked

Re: WaitFor fails while Prompt works

by novanstar @, (6030 days ago) @ novanstar

Oh, it's not my typo. The forum escape the escape char... ls\n

locked

Re: WaitFor fails while Prompt works

by wodDamir @, (6030 days ago) @ novanstar

Hi,

Honestly, I can't see a reason why the Prompt version would work, since it doesn't affect any of other methods that you used.

Please try the suggestions that I asked you to, and let me know if that helps?

Regards,
Damba

locked

Re: WaitFor fails while Prompt works

by novanstar @, (6028 days ago) @ wodDamir

Hi,

Honestly, I can't see a reason why the Prompt version would work, since it doesn't affect any of other methods that you used.

Please try the suggestions that I asked you to, and let me know if that helps?

Regards,
Damba

Hi, I have tried per suggestion. And it works. :) Thanks.
BTW, If I expect a command won't return back to command prompt (it need CTRL+C to return), what's the wodSSH API method combination I can use to receive the result after running the command, then based on the result to issue CTRL+C? (Send, WaitFor, and Send(^c)? )

Thanks,

locked

Re: WaitFor fails while Prompt works

by wodDamir @, (6028 days ago) @ novanstar

Hi,

In that case, you'll need to catch an error, and code like this to send CTRL-C :

[code]
byte a = 3;
char b = Convert.ToChar(a);
ssh1.Send(b.ToString());
[/code]

Hope this helps.

Regards,
Damba

locked

Re: WaitFor fails while Prompt works

by novanstar @, (6028 days ago) @ wodDamir

Hi Damba,
Thanks for your great support.

Regards,
novanstar

locked