Expect doesn't support Windows 2012 properly

Posted by peterp on 2014-03-26 04:25
Forums: Expect discussion | OS: Windows

Hi.

I have an Expect script that worked fine on Win2003 & Win2012, but stopped to catch the output of console application on Win2012R2. Although *some* console applications still work fine Expect fails to get the output from many of them.

I investigated the issue and I know what the problem is:
Expect is working like a debugger - it puts breakpoints on certain addresses in the process it is spawning (functions like WriteConsoleA & WriteFile, etc.) and when these functions are called, it access the memory on the spawned process and get the output. However, the way Windows API is implemented changed in Win2012, causing this method to stop working...

On Win2008, when the console process calls WriteFile, inside its implementation, if Windows finds out that the file handle is actually the stdout handle, it redirects itself to the address of WriteConsole. That means that from Expect point of view, when the process calls WriteFile, Expect catches 2 breakpoints - one for WriteFile and then another one for WriteConsole.
The first breakpoint does nothing, but the second breakpoint cause Expect to read the output buffer from the process.

On Windows2012, however, the implementation is different - WriteFile doesn't cause the breakpoint for WriteConsole to happen and because Expect doesn't do anything when it catches WriteFile, any application that uses WriteFile and doesn't call WriteCansole *will not be handled correctly by Expect*.

In a nutshell - the way Expect is "listening" on console applications today means that on Win2012 it won't handle any application that write to the console using WriteFile (which are many of them, you''l be surprised to know...)
From my point of view is means that Expect is not really supported on Win2012 .

Is this a known issue?
Does anyone knows when this is going to be handled?

PeterP

grahams
ActiveState Staff
Wed, 2014-03-26 08:45

We have had reports of issues with Expect on 2012 R2, and your description seems like you have pinned down the root cause of them.

Given how deep you have looked into the code, do you see a possible solution?

peterp | Wed, 2014-03-26 08:56

Hi grahams.

This is what I think about:

Both breakpoints (WriteFile & WriteConsole) are handled today by Expect, but the code that used for WriteFile (OnXWriteFile, I think) it disabled by "#ifdef 0". Probably, when it was developed someone saw that handling is done twice when WriteFile is called, and decided to fix it.

I think that bringing back that code (and fix it a bit) and making sure it works correctly is a must.
It can be done in 2 ways:
1. run it only if we are on a certain OS version (2012 or higher), instead of using #ifdef 0.
2. run it always but use some kind of a signal that will prevent it from running again when getting to the WriteConsole breakpoint.

ejikata | Wed, 2014-05-28 02:47

Hi,

I also found the same problem on Expect spawn on Windows 8, 8.1 and Server 2012. :-(

So does it have plan to support them, and when?
And are there any work-around to make it work on these Windows?

asilver | Mon, 2015-09-21 19:07

Hi,
Has there been any progress on this? I'm also hitting similar problems with Expect scripts only when run on Windows Server 2012.

Thx
Asilver