TimeOut Issue - I am able to receive data only after the timeout period.

0 votes
asked Jun 22, 2012 by Sajad Karim (200 points)
edited Jul 16, 2014

As per my understanding we use timeout to suspend any operation if it's taking time longer than usual.

Issue is: I am using following method of class VirtualTerminal, but I am able to receive data only after the timeout period has expired.

public Match Expect(Regex pattern, int maximumWaitTime);

Even I have provided timeout:60000 (60Sec) and it's returning after 60Sec, though I am receiving same data when setting timeout: 2000.

Please can any one help me in this regard.

I have used following code to calculate time difference:
DateTime t1 = DateTime.Now;
string _response = m_shell.Expect("regex:(.*)");
string _lines = m_shell.ReceivedData;
DateTime t2 = DateTime.Now;
Logger.WriteLog(String.Format(" Response Time Diff.: {0}", t2 - t1));

Thanks.

2 Answers

+1 vote
answered Jun 22, 2012 by Lukas Matyska (47,270 points)
edited Jul 12, 2012

At the first place I would like to clarify that the mentioned method: public Match Expect(Regex pattern, int maximumWaitTime); is a method from the VirtualTerminal class while the example you included uses a method from the VirtualShell class: public string Expect(string regexPattern).

However, the behavior of both methods is the same: Receives data until the specified pattern is found, but no longer than a timeout period.

The issue in your example is caused by "incorrect" input regex pattern. Please note, that "regex:" prefix is not wanted, just pass the pattern directly.

So, your example behaves correctly: wait until pattern "regex:(.*)" is found. Because it is not found, method returns null after the specified timeout. The m_shell.ReceivedData property contains all received data up to that time.

Also please note, that m_shell.Expect(".*") matches everything, which is also an empty string. It leads to a specific behavior: if no data are buffered, no data are received and the method returns immediately with success. You should rather use m_shell.Expect(".+") to receive at least one character (or more if available).

I would like to also point at the m_shell.Match property. The idea is as follows: The Expect method returns received data without the matched pattern. The Match property returns a data matched by the specified pattern. The ReceivedData property returns all received data. So, there is such an equality:

  • output of the Expect method concatenated with the Match property is equal to the ReceivedData property
  • C#: shell.Expect("pattern") + shell.Match == shell.ReceivedData
  • VB: shell.Expect("pattern") & shell.Match = shell.ReceivedData
commented Jun 22, 2012 by Sajad Karim (200 points)
edited Jun 22, 2012

Yes, I was providing invalid regex.

Thanks a lot Lukas.

0 votes
answered Jul 16, 2014 by Pavel Matyska (10,840 points)
edited Jul 16, 2014

Hi, we have just release new Scripting API in 2014-R2 release. You can read more of its features on Scripting features page.

...