WaitFor fails while Prompt works - WeOnlyDo Discussion board

WaitFor fails while Prompt works (General questions)

by novanstar, Saturday, November 01, 2008, 00:06 (5866 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();

Re: WaitFor fails while Prompt works

by wodDamir, Saturday, November 01, 2008, 14:42 (5865 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

Re: WaitFor fails while Prompt works

by novanstar, Saturday, November 01, 2008, 19:35 (5865 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,

Re: WaitFor fails while Prompt works

by novanstar, Saturday, November 01, 2008, 19:38 (5865 days ago) @ novanstar

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

Re: WaitFor fails while Prompt works

by wodDamir, Saturday, November 01, 2008, 20:42 (5865 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

Re: WaitFor fails while Prompt works

by novanstar, Monday, November 03, 2008, 23:21 (5863 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,

Re: WaitFor fails while Prompt works

by wodDamir, Monday, November 03, 2008, 23:24 (5863 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

Re: WaitFor fails while Prompt works

by novanstar, Tuesday, November 04, 2008, 00:35 (5863 days ago) @ wodDamir

Hi Damba,
Thanks for your great support.

Regards,
novanstar