WaitFor Procedures - WeOnlyDo Discussion board

WaitFor Procedures (General questions)

by bmclellan, Tuesday, April 29, 2008, 15:46 (6052 days ago)

Hello,

I am using the WaitFor command as a way to start capturing my data.

The problem I am having is sometimes, the prompt I am waiting for does not show up, and the Waitfor command causes an exception.

The logic I am hoping to do is this:

WaitFor( Prompt ) (Maximum wait 30 seconds)

if WaitFor fails (*Don't kick me off the system!*)
Get the data that is in the receive buffer
... do my logic to see if it still has what I need

Continue sending additional commands to my host system

I am using Winbatch as my programming language, but if you have a VBish example, that would be great!

Thanks for your help!
Barry

Re: WaitFor Procedures

by wodDamir, Tuesday, April 29, 2008, 16:11 (6052 days ago) @ bmclellan

Hi Barry,

You can still receive what is in the buffer by using Receive method. Also, in VB we have On Error GoTo statement, which prevents application from throwing an exception (I'm not sure if that exists in WinBatch and how errors are handled there). So the code would look something like this:

On Error GoTo ErrorHandler
some_variable = ssh1.WaitFor prompt , 30

ErrorHandler:
some_variable = ssh1.Receive

Can you try something like that in WinBatch?

Regards,
Damba

Re: WaitFor Procedures

by bmclellan, Tuesday, April 29, 2008, 16:34 (6052 days ago) @ wodDamir

Thanks Damba,

I'll give it a shot!

If I hit the WaitFor timeout, will it disconnect my session?


Barry

Re: WaitFor Procedures

by woddrazen, Tuesday, April 29, 2008, 16:54 (6052 days ago) @ bmclellan

Barry,


Yes, you will be disconnected from server.


Drazen

Re: WaitFor Procedures

by bmclellan, Tuesday, April 29, 2008, 17:28 (6051 days ago) @ woddrazen

Hmm,

Is there a way to set it so that it does not disconnect?

If my waitFor fails, I would like to be able to recover without having to go through the entire log in sequence again!

Even if there was a new flag of somesort in the Waitfor field to not disconnect on failure.


Barry

Re: WaitFor Procedures

by woddrazen, Tuesday, April 29, 2008, 17:47 (6051 days ago) @ bmclellan

Barry,


... ooops I have just tried and find out that you will not be disconnected from server if WaitFor fails. So I think you can do whatever you want.

Can you please try it and let us know how it goes.


Drazen

Re: WaitFor Procedures

by bmclellan, Tuesday, April 29, 2008, 20:04 (6051 days ago) @ woddrazen

Thanks! Tryign it now!

One Question, using the regex expression:

WaitFor( regex:[1H@[7mlist|is an invalid|Object omitted;] ,30)

I already have a '[' in my list, do you know how to escape that character? I can't seem to figure it out!

Barry

Re: WaitFor Procedures

by woddrazen, Tuesday, April 29, 2008, 21:14 (6051 days ago) @ bmclellan

Barry,


If this is UNIX server. I think you can change your prompt using export PS1 command to anything you like.

[code]Debug.Print ssh1.Execute( export PS1= drazenWeonlydo.com + vbLf, drazenWeonlydo.com )

or

ssh1.Send export PS1= drazenWeonlydo.com + vbLf[/code]

Using this code I changed prompt to drazenWeonlydo.com


Drazen

Re: WaitFor Procedures

by bmclellan, Tuesday, April 29, 2008, 21:46 (6051 days ago) @ woddrazen

Thanks Drazen,

Unfortunately this is not a UNIX prompt, so I can't change it, it's a proprietary interface using SSH.

I tried the timeout option with WaitFor, and it does work however some of my regexp expressions were failing with the following message:

'Regular expression error. range out of order in character class.'

This was my regex query:
regex:[7mdisplay data-format 2|invalid|Not assigned;]

Is there some kind of regex order I am missing?

Re: WaitFor Procedures

by woddrazen, Tuesday, April 29, 2008, 23:07 (6051 days ago) @ bmclellan

Barry,

Can you please try this:[code]ssh1.WaitFor ( regex:1H@+\[+7mlist|is an invalid|Object omitted; )[/code] Drazen

Re: WaitFor Procedures

by bmclellan, Wednesday, April 30, 2008, 20:21 (6050 days ago) @ woddrazen

This is fantastic thanks!! I wasn't even close!

... you wouldn't know how to get regex to ignore case would you?


Barry

Re: WaitFor Procedures

by wodDamir, Wednesday, April 30, 2008, 20:38 (6050 days ago) @ bmclellan

Barry,

We don't know all the expressions that can be used. However, perhaps you should look at the following link:

http://www.regular-expressions.info/modifiers.html

I believe what you are looking for is modifier /i .

Also, all the combinations, and instructions on using regex can be found there.

Hope this helps.

Regards,
Damba

Re: WaitFor Procedures

by bmclellan, Wednesday, April 30, 2008, 20:48 (6050 days ago) @ wodDamir

Perfect!

Thanks very much for your help Damba, this support is excellent!


Barry

Re: WaitFor Procedures

by bmclellan, Thursday, May 01, 2008, 16:41 (6050 days ago) @ bmclellan

Hi Damba,

Sorry to keep stretching this out, but is the /i option supported?

I am trying every swtich I can find to disable case insensitivity:

but having no luck using
WaitFor('regex:/i','1H',Esc,'+[+7mObject List|is an invalid')
or
WaitFor('regex:(-i)','1H',Esc,'+[+7mObject List|is an invalid')

or
WaitFor('regex:(-ism)','1H',Esc,'+[+7mObject List|is an invalid')

unfortunately most regexp options I have found all set an object. Event the handy site: http://www.dotnetcoders.com/web/Learning/Regex/RegexTester.aspx has a checkbox for case sensitivity!

Thanks
Barry

Re: WaitFor Procedures

by woddrazen, Thursday, May 01, 2008, 20:33 (6049 days ago) @ bmclellan

Barry,


Please try this[code]ssh1.WaitFor ( regex:(?i)1H@+[+7mlisT|is an invaliD|Object omitteD;(?-i) )[/code]Drazen

Re: WaitFor Procedures

by bmclellan, Friday, May 02, 2008, 03:49 (6049 days ago) @ woddrazen

Thanks again! I wasn't even close.

I can see the next version of your help file having a few of these combinations!