Wine 下重定向 Windows 命令行程序的 stdout

Wine 下重定向 Windows 命令行程序的 stdout

我用 wine 运行一个 Windows 命令行程序(我无法访问)。它显然向标准输出写入了一些内容,我正在尝试捕获该输出,但我无法重定向它。

无论我将 stdout 或 stderr 重定向到文件,程序输出仍然打印在控制台上,并且不会写入文件。当我重定向 stderr 时,wine 输出消失,但程序的输出仍然打印在屏幕上。

wine program.exe > out   # File is empty, program output printed on screen
wine program.exe 2> out  # Wine output gets redirected to file, program output still printed on screen

如果我重定向两者,输出既不会打印在屏幕上,也不会写入文件。

编辑:在 Windows 上,行为类似,但在重定向两者时,所有内容仍然打印在屏幕上。

以下是一些具有完整输出的示例。

$ wine program.exe
fixme:winediag:start_process Wine Staging 1.9.23 is a testing version containing experimental patches.
fixme:winediag:start_process Please mention your exact version when filing bug reports on winehq.org.

output by program.exe

fixme:msvcrt:__clean_type_info_names_internal (0x100aaa54) stub

当我尝试重定向输出时,会发生这种情况:

$ wine program.exe > out 2>&1
$ cat out
fixme:winediag:start_process Wine Staging 1.9.23 is a testing version containing experimental patches.
fixme:winediag:start_process Please mention your exact version when filing bug reports on winehq.org.
fixme:msvcrt:__clean_type_info_names_internal (0x100aaa54) stub

即,程序的控制台输出完全丢失。该程序仍然可以正常工作并写入一些它应该写入的文件。作为检查,我对 pngcrush 做了同样的事情,并且得到了我所期望的结果。没有重定向:

$ wine pngcrush_1_8_10_w32.exe test.png out.png
fixme:winediag:start_process Wine Staging 1.9.23 is a testing version containing experimental patches.
fixme:winediag:start_process Please mention your exact version when filing bug reports on winehq.org.

 | pngcrush-1.8.10
 |    Copyright (C) 1998-2002, 2006-2016 Glenn Randers-Pehrson
 |    Portions Copyright (C) 2005 Greg Roelofs
 | This is a free, open-source program.  Permission is irrevocably
 | granted to everyone to use this version of pngcrush without
 | payment of any fee.
 | Executable name is pngcrush_1_8_10_w32.exe
 | It was built with   bundled libpng-1.6.26
 | and is running with bundled libpng-1.6.26
 |    Copyright (C) 1998-2004, 2006-2016 Glenn Randers-Pehrson,
 |    Copyright (C) 1996, 1997 Andreas Dilger,
 |    Copyright (C) 1995, Guy Eric Schalnat, Group 42 Inc.,
 | and bundled zlib-1.2.8.1-motley, Copyright (C) 1995 (or later),
 |    Jean-loup Gailly and Mark Adler,
 | and using "clock()".
 | It was compiled with gcc version 4.8.0 20121015 (experimental).

  Recompressing IDAT chunks in test.png to out.png
   Total length of data found in critical chunks            =    431830
   Critical chunk length, method   1 (ws 15 fm 0 zl 4 zs 0) =    495979
   Critical chunk length, method   2 (ws 15 fm 1 zl 4 zs 0) >    495979
   Critical chunk length, method   3 (ws 15 fm 5 zl 4 zs 1) =    495354
   Critical chunk length, method   6 (ws 15 fm 5 zl 9 zs 0) =    457709
   Critical chunk length, method   9 (ws 15 fm 5 zl 2 zs 2) >    457709
   Critical chunk length, method  10 (ws 15 fm 5 zl 9 zs 1) =    451813
   Best pngcrush method        =  10 (ws 15 fm 5 zl 9 zs 1) =    451813
     (4.63% critical chunk increase)
     (4.63% filesize increase)

CPU time decode 4.407583, encode 17.094248, other 4294967296.000000, total 17.180143 sec

带有重定向:

$ wine pngcrush_1_8_10_w32.exe test.png out.png > out 2>&1
$ cat out
fixme:winediag:start_process Wine Staging 1.9.23 is a testing version containing experimental patches.
fixme:winediag:start_process Please mention your exact version when filing bug reports on winehq.org.

 | pngcrush-1.8.10
 |    Copyright (C) 1998-2002, 2006-2016 Glenn Randers-Pehrson
 |    Portions Copyright (C) 2005 Greg Roelofs
 | This is a free, open-source program.  Permission is irrevocably
 | granted to everyone to use this version of pngcrush without
 | payment of any fee.
 | Executable name is pngcrush_1_8_10_w32.exe
 | It was built with   bundled libpng-1.6.26
 | and is running with bundled libpng-1.6.26
 |    Copyright (C) 1998-2004, 2006-2016 Glenn Randers-Pehrson,
 |    Copyright (C) 1996, 1997 Andreas Dilger,
 |    Copyright (C) 1995, Guy Eric Schalnat, Group 42 Inc.,
 | and bundled zlib-1.2.8.1-motley, Copyright (C) 1995 (or later),
 |    Jean-loup Gailly and Mark Adler,
 | and using "clock()".
 | It was compiled with gcc version 4.8.0 20121015 (experimental).

  Recompressing IDAT chunks in test.png to out.png
   Total length of data found in critical chunks            =    431830
   Critical chunk length, method   1 (ws 15 fm 0 zl 4 zs 0) =    495979
   Critical chunk length, method   2 (ws 15 fm 1 zl 4 zs 0) >    495979
   Critical chunk length, method   3 (ws 15 fm 5 zl 4 zs 1) =    495354
   Critical chunk length, method   6 (ws 15 fm 5 zl 9 zs 0) =    457709
   Critical chunk length, method   9 (ws 15 fm 5 zl 2 zs 2) >    457709
   Critical chunk length, method  10 (ws 15 fm 5 zl 9 zs 1) =    451813
   Best pngcrush method        =  10 (ws 15 fm 5 zl 9 zs 1) =    451813
     (4.63% critical chunk increase)
     (4.63% filesize increase)

CPU time decode 4.339310, encode 17.137527, other 4.294083, total 17.182100 sec

导致其他程序不起作用的原因是什么?

Wine stdout stderr io 重定向

答案1

您可以使用 tmux 终端多路复用器来捕获标准输出capture-pane

答案2

创建 .bat 脚本并从那里重定向怎么样?

binary.exe args > output.txt并简单地运行wine start script.bat

我刚刚尝试过,效果很好

答案3

这个问题有一个缺陷:wine program.exe >out不是重定向输出自program.exe——它正在重定向自身的输出wine这可能与program.exe 输出相同,也可能不同。

当 shell 处理该命令时,它会看到该命令是wine。它还发现您想要将 的输出重定向wine到文件out。它(大部分)忽略program.exe——仅处理它以进行变量扩展等。但对于 shell 来说,它只是传递给 的文本参数wine。您也可以输入wine foorbar.exe >out,shell 不会关心或检查是否foorbar.exe确实存在。 shell 只是将其传递给wine,然后让我们wine弄清楚如何处理它。

shell 打开文件out以写入任何输出(如果>使用则在截断模式下,如果>>使用则在追加模式下)。然后 shell 尝试找到wine二进制文件/可执行文件。

如果找不到wine,它会打印一条错误消息,关闭该文件out而不写入任何内容(它是一个空文件),并显示一个新的命令提示符。

如果命令wine 找到后,它使用单个参数执行它program.exe,并将 的输出绑定wine到 的文件句柄outwine永远不会看到 ,>out因为 shell 已经处理了它。

wine现在启动,并执行任何操作来设置类似 Windows 的环境,该环境可能包含也可能不包含其他输入/输出 (i/o) 流。这一切都取决于您如何配置和设置wine。这些流可能会或可能不会(通过)绑定到执行之前设置的(或您使用的任何 shell)wine的输入/输出流。bashwine

此时,wine尝试定位并执行program.exe.由于wine从未看到>out重定向,所以确实如此不是设置任何附加重定向。

正如您所看到的,现在情况变得相当复杂,许多不同的 i/o 流与许多不同的进程和/或文件相关联。

Wine 有多种工具、操作模式和配置来处理类似的各种情况,例如wineconsole适用于“CUI”(控制台模式)程序的情况。您必须阅读 Wine 文档来了解如何使用这些工具并设置任何所需的环境、如何设置 CUI 模式重定向等等。

所有这些都太复杂了,无法在这里发布答案——您将必须阅读文档并尝试自己解决,如果您遇到问题,还可以发布其他更具体的问题和详细信息。

所以这个答案的“tl;dr”版本是:没有可以在这里发布的答案,因为它超出了本网站的范围和目的。原来的问题提出了太多不正确关于整个系统如何工作的假设。

相关内容