Two windows console programming questions (C/Win32)
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.
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.
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).
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).
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
Popular Topics
Advertisement