windows-console

Getting terminal size in c for windows?

本秂侑毒 提交于 2019-12-17 06:38:45
问题 How to check ymax and xmax in a console window, under Windows, using plain c? There is this piece of code for linux: #include <stdio.h> #include <sys/ioctl.h> int main (void) { struct winsize max; ioctl(0, TIOCGWINSZ , &max); printf ("lines %d\n", max.ws_row); printf ("columns %d\n", max.ws_col); } Now I wonder how can I do the same for windows. I tried winioctl.h but it does not define struct winsize nor any other with a similar name. Any tips? Thanks. PS. In linux you also can find the

Using STDIN with an AllocConsole()

泄露秘密 提交于 2019-12-14 03:41:57
问题 I have a third-party dll that I load into software that isn't mine, and I'm using AllocConsole() to create the standard windows CLI window so I have an easy means of outputting debug messages. My problem is though, is that it ignores any kind of input. I just want to be able to use the console I allocated and enable the ability for me to give it some input. 回答1: Thanks to Ben Voigt, I was able to cause the console to take input after I allocated it by doing: freopen("CONIN$", "r", stdin);

How would I write a batch script to either minimise all cmd windows or minimise a window with a given name? [closed]

好久不见. 提交于 2019-12-14 03:26:00
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . The windows that I am trying to minimise are already running so start /min is not an option. 回答1: It can be done with an vbscript hybrid. @echo off set "lookFor=Calculator" for /f "tokens=2 delims=," %%A in ('tasklist /nh /fo csv /fi "WINDOWTITLE eq %lookfor%"') do set "pid=%%~A"

Python script doesn't print output in command prompt

北城余情 提交于 2019-12-14 03:05:36
问题 I need some advice with a Python script. I'm still new and learned it by myself. I found the script on Google. After I retype it, it doesn't print the result in the console. How can the result of the script be shown in the console? Details as below: C:\Python27>test1.py af8978b1797b72acfff9595a5a2a373ec3d9106d C:\Python27> After I press enter, nothing happens. Should the result be shown or not? Here's the code that I retyped: #!/usr/bin/python #coding: ascii import requests import sys import

How to determine the currently active code page from a Java console application on Windows?

自闭症网瘾萝莉.ら 提交于 2019-12-13 10:23:31
问题 This is a simple Java application which displays the default code page on Windows: package doscommand; import java.io.IOException; import java.io.InputStream; public class DosCommand { public static void main(String[] args) throws IOException { InputStream in = Runtime.getRuntime().exec("chcp.com").getInputStream(); int ch; StringBuilder chcpResponse = new StringBuilder(); while ((ch = in.read()) != -1) { chcpResponse.append((char) ch); } System.out.println(chcpResponse); // For example:

How to CancelSynchronousIo() on WaitForSingleObject() waiting on stdin?

微笑、不失礼 提交于 2019-12-13 07:39:59
问题 On Windows 10, I'm waiting for input from the console using WaitForSingleObject ( GetStdHandle(STD_INPUT_HANDLE), ... ) and to cancel this waiting using CancelSynchronousIo(). But the cancellation does nothing (returns 0 and GetLastError() is ERROR_NOT_FOUND ). Any idea what I could be doing wrong? Should I be able to cancel this waiting for new input on stdin? (I actually want to do this with any HANDLE whose GetFileType() is FILE_TYPE_CHAR , not only stdin, but stdin is certainly the most

How to use ESC sequences to set foreground colors?

做~自己de王妃 提交于 2019-12-13 03:44:04
问题 I'm writing a dynamic color palette for console terminal. The thing is to get ANSI ESC sequences to work within a default wincon terminal is enough to set those flags to the handles of the console: DWORD dwRequestedOutModes = ENABLE_VIRTUAL_TERMINAL_PROCESSING | DISABLE_NEWLINE_AUTO_RETURN; DWORD dwRequestedInModes = ENABLE_VIRTUAL_TERMINAL_INPUT; but using them is another thing. Right now my console engine outputs screen buffer made with CHAR_INFO with WriteConsoleOutputW() , but CHAR_INFO

Python.exe opens in a new console window

China☆狼群 提交于 2019-12-13 03:41:34
问题 I used to run Python scripts from my Windows command line, and all the prints were printed in the same console. Now something happened on my machine (Windows 10), and when I launch a Python script from the command line (i.e. open a Command Prompt and run python <my_script.py> ), Windows opens a new window (titled with the absolute path of python.exe). This windows closes automatically at the end of the execution, so that I can't see the output. How do I go back to printing output in the same

How do I write a Unicode string to the console screen buffer?

前提是你 提交于 2019-12-12 19:14:03
问题 Given a handle (hStdOut here) to the standard output device , I use the following 2 procedures to write an arbitrary string from a console application: Excerpt: procedure Send(const s: string); var len: cardinal; begin len:=Length(s); WriteFile(hStdOut,s[1],len,len,nil); end; procedure SendLn(const s: string); begin Send(s + #13#10); end; My trouble: This statement doesn't render correctely the string as I expected: SendLn('The harder they come...'); My Question: Is there a "WideString"

Clear screen with Windows “cls” command in Java console application

假如想象 提交于 2019-12-12 18:25:11
问题 I am working on a game that involves clearing the screen after each turn for readability. The only problem is I cannot use the Windows command prompt-based "cls" command and it does not support ANSI escape characters. I used Dyndrilliac's solution on the following page but it resulted in an IOException: Java: Clear the console Replacing "cls" with "cmd \C cls" only opened a new command prompt, cleared it, and closed it without accessing the current console. How do I make a Java program