2011-09-23 1126 views
0

我写了一个python程序,它通过管道重定向来读取另一个进程的stdout。什么是Windows错误0“ERROR_SUCCESS”是什么意思?

print "[Input Thread] ", self.inputPipe.readline(ii) 

该错误是IO错误:: 但是,程序在此行抽吸[错误0]错误

我发现窗口的说明errno设置为0。这使得混淆,因为它定义为:

The operation completed successfully.

为什么操作成功完成会导致错误?

+0

通常,当你的错误代码'0',通常表示成功(如没有问题)。显然,无论你在那里做了什么,都认为出现了问题,并在没有一个问题时打印出“错误信息”。 –

+2

'ERROR_SUCCESS'表示WinAPI中的“无错误”。它的前缀是ERROR_,它与“定义命名空间”相同。我会更加关注IOError位,尽管我不知道是什么原因造成的。 – 2011-09-23 04:49:19

回答

1

我知道这是有点古老,但花了相当多的时间试图找到一个完整的答案没有成功。所以我想我会分享我的想法。

发生这种情况的完整答案是当您调用“失败”的pInvoke方法但不是因为错误。

搞起你认为

例如假设你需要解开一个窗钩,但这样做的因位的意大利面条或在你的对象架构防御式编程的偏执水平打了两次电话。

// hook assigned earlier 

// now we call our clean up code 
if (NativeMethods.UnhookWindowsHookEx(HookHandle) == 0) 
{ 
    // method succeeds normally so we do not get here 
    Log.ReportWin32Error("Error removing hook", Marshal.GetLastWin32Error()); 
} 

// other code runs, but the hook is never reattached, 
// due to paranoid defensive program you call your clean up code twice 
if (NativeMethods.UnhookWindowsHookEx(HookHandle) == 0) 
{ 
    // pInvoke method failed (return zero) because there was no hook to remove 
    // however there was no error, the hook was already gone thus ERROR_SUCCESS (0) 
    // is our last error 
    Log.ReportWin32Error("Error removing hook", Marshal.GetLastWin32Error()); 
}