Can you redirect Tee-Object to standard out?

To complement zett42’s helpful answer: If you’re running PowerShell (Core) 7+, you can pass the file path that represents the terminal (console) to the (positionally implied) -FilePath parameter (in Windows PowerShell, this causes an error, unfortunately – see bottom section): # PowerShell 7+ only # Windows Get-Content data.txt | Tee-Object \\.\CON | data_processor.exe # Unix-like … Read more

Output Unicode strings in Windows console

I have verified a solution here using Visual Studio 2010. Via this MSDN article and MSDN blog post. The trick is an obscure call to _setmode(…, _O_U16TEXT). Solution: #include <iostream> #include <io.h> #include <fcntl.h> int wmain(int argc, wchar_t* argv[]) { _setmode(_fileno(stdout), _O_U16TEXT); std::wcout << L”Testing unicode — English — Ελληνικά — Español.” << std::endl; } … Read more

How to use the new support for ANSI escape sequences in the Windows 10 console?

The problem is that the Python interpreter doesn’t enable the processing of ANSI escape sequences. The ANSI sequences work from the Windows command prompt because cmd does enable them. If you start Python from the command prompt you’ll find the ANSI sequences do work, including the ones for enabling and disabling the cursor. That’s because … Read more

Colored text output in PowerShell console using ANSI / VT100 codes

Note: The following applies to regular (legacy) console windows on Windows (provided by conhost.exe), which are used by default, including when a console application is launched from a GUI application. By contrast, the console windows (terminals) provided by Windows Terminal provide support for VT / ANSI escape sequences by default, for all console applications. While … Read more

How can I get the mouse position in a console program?

You’ll need to use the *ConsoleInput family of methods (peek, read, etc). These operate on the console’s input buffer, which includes keyboard and mouse events. The general strategy is: wait on the console’s input buffer handle (ReadConsoleInput) determine the number of waiting events (lpNumberOfEventsRead) handle them as you see fit (i.e. MOUSE_EVENT and MOUSE_EVENT_RECORD) You’ll … Read more

C++ Executing CMD Commands

Redirecting the output to your own pipe is a tidier solution because it avoids creating the output file, but this works fine: ShellExecute(0, “open”, “cmd.exe”, “/C ipconfig > out.txt”, 0, SW_HIDE); You don’t see the cmd window and the output is redirected as expected. Your code is probably failing (apart from the /C thing) because … Read more

How to avoid console window with .pyw file containing os.system call?

You should use subprocess.Popen class passing as startupinfo parameter’s value instance of subprocess.STARTUPINFO class with dwFlags attribute holding subprocess.STARTF_USESHOWWINDOW flag and wShowWindow attribute holding subprocess.SW_HIDE flag. This can be inferred from reading lines 866-868 of subprocess.py source code. It might be necessary to also pass subprocess.CREATE_NEW_CONSOLE flag as a value of creationflags parameter as you … Read more

Getting terminal size in c for windows?

This prints the size of the console, not the buffer: #include <windows.h> int main(int argc, char *argv[]) { CONSOLE_SCREEN_BUFFER_INFO csbi; int columns, rows; GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi); columns = csbi.srWindow.Right – csbi.srWindow.Left + 1; rows = csbi.srWindow.Bottom – csbi.srWindow.Top + 1; printf(“columns: %d\n”, columns); printf(“rows: %d\n”, rows); return 0; } This code works because srWindow “contains the … Read more