-1

I'm a bit puzzled about the behavior of the command line in Windows, but hopefully somebody can help me out.

I am not seeing any output of my application in the Windows command line. I tried start "" "myapplication.exe", and other options, to start the application. As a result, no error is thrown, just a blank line is created and I'm back at the command line.

I broke the app down to these few simple lines:

#include <stdio.h>
int main(int argc, char **argv)
{
    printf("No base path defined!\n");
    fflush( stdout );
    return 0;
}

I compile the app without errors using the gcc provided in MSYS2 on Windows. I get the correct output when I use the msys2 terminal, or start the app from a python script using subprocess.run(). When I pipe the output to a file from cmd.exe, the file remains empty.

Edits according to Mofis comments:

  • There are no keys in %SystemRoot%\System32\reg.exe QUERY "HKCU\Software\Microsoft\Command Processor. Output is:ERROR: The system was unable to find the specified registry key or value. I also checked directly in the regedit, there is nothing similar to it.
  • The output of %SystemRoot%\System32\reg.exe QUERY "HKCU\Console" is the following:

HKEY_CURRENT_USER\Console

ColorTable00    REG_DWORD    0xc0c0c
ColorTable01    REG_DWORD    0xda3700
ColorTable02    REG_DWORD    0xea113
ColorTable03    REG_DWORD    0xdd963a
ColorTable04    REG_DWORD    0x1f0fc5
ColorTable05    REG_DWORD    0x981788
ColorTable06    REG_DWORD    0x9cc1
ColorTable07    REG_DWORD    0xcccccc
ColorTable08    REG_DWORD    0x767676
ColorTable09    REG_DWORD    0xff783b
ColorTable10    REG_DWORD    0xcc616
ColorTable11    REG_DWORD    0xd6d661
ColorTable12    REG_DWORD    0x5648e7
ColorTable13    REG_DWORD    0x9e00b4
ColorTable14    REG_DWORD    0xa5f1f9
ColorTable15    REG_DWORD    0xf2f2f2
CtrlKeyShortcutsDisabled    REG_DWORD    0x0
CursorColor    REG_DWORD    0xffffffff
CursorSize    REG_DWORD    0x19
DefaultBackground    REG_DWORD    0xffffffff
DefaultForeground    REG_DWORD    0xffffffff
EnableColorSelection    REG_DWORD    0x0
ExtendedEditKey    REG_DWORD    0x1
ExtendedEditKeyCustom    REG_DWORD    0x0
FaceName    REG_SZ    __DefaultTTFont__
FilterOnPaste    REG_DWORD    0x1
FontFamily    REG_DWORD    0x0
FontSize    REG_DWORD    0x100000
FontWeight    REG_DWORD    0x0
ForceV2    REG_DWORD    0x1
FullScreen    REG_DWORD    0x0
HistoryBufferSize    REG_DWORD    0x32
HistoryNoDup    REG_DWORD    0x0
InsertMode    REG_DWORD    0x1
LineSelection    REG_DWORD    0x1
LineWrap    REG_DWORD    0x1
LoadConIme    REG_DWORD    0x1
NumberOfHistoryBuffers    REG_DWORD    0x4
PopupColors    REG_DWORD    0xf5
QuickEdit    REG_DWORD    0x1
ScreenBufferSize    REG_DWORD    0x23290078
ScreenColors    REG_DWORD    0x7
ScrollScale    REG_DWORD    0x1
TerminalScrolling    REG_DWORD    0x0
TrimLeadingZeros    REG_DWORD    0x0
WindowAlpha    REG_DWORD    0xff
WindowSize    REG_DWORD    0x1e0078
WordDelimiters    REG_DWORD    0x0

HKEY_CURRENT_USER\Console\%%Startup
HKEY_CURRENT_USER\Console\%SystemRoot%_System32_WindowsPowerShell_v1.0_powershell.exe
HKEY_CURRENT_USER\Console\%SystemRoot%_SysWOW64_WindowsPowerShell_v1.0_powershell.exe

In the meantime i tried something different. I compiled the same code in Microsoft visual Studio 22. Now i finally see my output in the cmd. So somehow the problem evolves from compiling with gcc/Msys2?

I see the output for both application compiled with the different environoments when i run via subprocess from python as before. I only noticed the encoding has changed when compiling with VS which would not be the issue. But of course i want to use the msys2 environment.

  • Setting "setvbuf(stdout, NULL, _IOLBF, 0);" does make a difference. When i compile with VS, i don't see any output anymore either in cmd or when starting with python. When i compile with setvbuf using msys2 i still see output in the subprocess started from python. However, still no output in cmd.

Edit2: Apparently not a new issue with MSYS2 on windows. (see https://github.com/docker/for-win/issues/262). I can get the output by piping into stdout and then display it with the type command:

application.exe > stdout 
type stdout 

Any better workaround would still be appreciated.

JohnnyDG
  • 1
  • 1

0 Answers0