Two windows console programming questions (C/Win32)

Started by
7 comments, last by SiCrane 16 years, 3 months ago
Question 1: How can I run console command line parameters/commands directly from within a C program without it being messy? Question 2: What is the Win32 approach to single character input? I want to grab a single character in a console without an "enter" keypress from the user and then move on. I'm having a heck of a time finding exactly what I need here. Thanks.
Advertisement
1) It'll always be messy. You just need to figure out which kind of mess you want.
2) Most compilers for Windows support a header called conio.h. In that header will usually be a function called getch() or _getch() that sounds like what you want.
Quote:Original post by SiCrane
2) Most compilers for Windows support a header called conio.h. In that header will usually be a function called getch() or _getch() that sounds like what you want.


Great, thanks. Looking into that further now.

Quote:1) It'll always be messy. You just need to figure out which kind of mess you want.

Can you point me to a discussion of it or tutorial? I keep googling and it always gives me something unrelated since the search terms have so many other topics in common and so far msdn hasn't had anything explicit that I have found.


Look up the system(), ShellExecute() and CreateProcess() functions. Or if you're feeling especially masochistic execl(), execle(), execlp() and execlpe().
I never recommend using conio.h . It’s not like a third party library. It’s a compiler dependent library, with absolutely no standardisation. Instead, you should use the Win32 API to implement the equivalent of getch.

See http://msdn2.microsoft.com/en-us/library/ms683462(VS.85).aspx (MSDN page) and http://www.mser.net/microsoft-developer-network/28/visual-c++-programming-281357.shtm (3rd reply).
How would exec* work in Windows? I don't seem to remember being able to fork a process.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
Are you asking how they're implemented or how to use them?
Quote:How would exec* work in Windows? I don't seem to remember being able to fork a process.
exec wouldn’t work in Windows. Can’t fork a process in Windows either. Sorry.

But it’s probably worth keeping in mind the fork/exec method on *NIX systems.
Quote:Original post by oler1s
exec wouldn’t work in Windows.

It's available via the MSVC CRT implementation, which means it can be used by programs compiled with MSVC or compilers that utilize the MSVC runtime like MinGW. See _exec on MSDN. Other compiler vendors like Borland support it as well.

This topic is closed to new replies.

Advertisement