【发布时间】:2015-03-31 05:06:44
【问题描述】:
我试图弄清楚如何测试文件是否被重定向到自身,例如.\command.exe file1 > file1
在 *nix 世界中,我只会使用这样的东西:
// Language agnostic...
if (file_dev == out_dev && file_ino == out_ino) {
printf("%s\n", "same file!");
}
但在 Windows 中,如果我尝试这样做:
// This (language) is Go...
// create fileStat...
// now stat stdout
outStat, err := os.Stdout.Stat()
// error check
if os.SameFile(fileStat, outStat) {
fmt.Println("same file!")
}
...我收到 IncorrectFunction 错误。
我阅读了这个 (https://stackoverflow.com/a/21070042/2967113) 问题,据我所知,您无法统计 stdout?
这是一个主要与语言无关的问题——我可以将任何内容翻译成 Go(我正在使用的语言)。我最关心的是如何,使用 Windows 的 ABI(API?),我会找到 stdout 被重定向到的位置。
【问题讨论】:
-
stackoverflow.com/users/2912665/garg-ankit 我拒绝了您的编辑,因为这是关于 Windows 的 A{B,P}I not Go... 抱歉。
-
没关系。重新阅读问题后对我有意义。