2

I run a Windows command line program (that I can not make accessible) with wine. It apparently writes something to stdout and I'm trying to capture that output, but I can't redirect it.

No matter if I redirect stdout or stderr to a file, the program output is still printed on the console and is not written to the file. When I redirect stderr, the wine output goes away, but the program's output is stilled printed on screen.

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

If I redirect both, the output is neither printed on screen nor written to the file.

Edit: On Windows, behavior is similar, but when redirecting both, everything is still printed on screen.

Here are some examples with the complete output.

$ 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

When I try to redirect the output, this happens:

$ 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

I.e., the program's console output is completely missing. The program still works fine and writes some files it's supposed to write. As a check, I did the same with pngcrush, and I get what I'd expect. Without redirection:

$ 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

With redirection:

$ 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

What could be the cause of that not working for the other program?

wine stdout stderr io-redirection

1
  • Does strace give any indication a) what the file descriptor for that output is or b) is that output even going though the unix layer? (Assuming strace or something like it can actually be run...)
    – thrig
    Dec 8 '16 at 15:26
0

You might use the tmux terminal multiplexer to capture stdout with a capture-pane

0

There is a flaw in the question: wine program.exe >out is not redirecting the output from program.exe -- it is redirecting the output from wine itself. That may or may not be the same as the program.exe output.

When the shell is processing the command, it sees that the command is wine. It also sees that you want to redirect the output of wine to the file out. It (mostly) ignores program.exe -- only processing it for variable expansion and such. But to the shell, it is simply a text argument passed to wine. You could also have typed wine foorbar.exe >out, and the shell does not care, or check, if foorbar.exe actually exists. The shell simply passes it to wine, and let's wine figure out what to do with it.

The shell opens the file out for writing any output (in truncation mode if > is used, or append mode if >> is used). Then the shell tries to locate the wine binary/executable.

If it cannot find wine, it prints an error message, closes the file out without writing anything to it (it's an empty file), and displays a new command prompt.

If the command wine is found, it executes it with a single argumen program.exe, and ties the output of wine to the file handle for out. wine never sees the >out as the shell has already handled that.

wine now starts up, and does whatever it does to set up a Windows'-like environment, which may or may not include other input/output (i/o) streams. That all depends on how you have configured and set up wine. Those streams may or may not be tied (by wine) to the input/output streams that bash (or whichever shell you use) set up before executing wine.

At this point, wine tries to locate and execute program.exe. Since wine never sees the >out redirection, it does not set up any additional redirection.

As you can see, the situation is becoming quite complex now with many different i/o streams associated to many different processes and/or files.

Wine has several tools, modes of operations, and configurations to handle a variety of situations like this, such as wineconsole which is meant for "CUI" (console mode) programs. You will have to read the Wine documentations to learn how to use these tools and set up any needed environments, how to set up CUI-mode redirection, and so on.

All of that is far too complex to post an answer here--you will have to read the documentation and try to figure it out on your own, and post other more specific questions and details, if you have trouble with that.

So the "tl;dr" version of this answer is: There is no answer that can be posted here because it exceeds the scope and purpose of this site. The original question makes too many incorrect assumptions about how the entire system works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.