- #1
timetraveldude
- 42
- 0
does anyone know how to run a console program in the background. This would be like the DNS or DHCP service that runs on a server waiting for a request.
thanks
thanks
Windows 2000chroot said:It might help to tell us what platform you're talking about.
- Warren
What I want to do is have a program wait for a keyboard event using the kbhit() function. The problem I am having is that the program will only register a keyboard event if the window the program started from is clicked upon. What I need to do is have the program detect a keyboard press reagardless of whether the windows running the program is in focus.dduardo said:Good luck. Microsoft's console isn't the most robust thing in the world.
Unix or Linux:
ctrl-z the program in the console. It will display a number along with the name of the program. Then you can do "bg [number]" or "fg [number]" depending if you want the program in the background or foreground
timetraveldude said:What I want to do is have a program wait for a keyboard event using the kbhit() function. The problem I am having is that the program will only register a keyboard event if the window the program started from is clicked upon. What I need to do is have the program detect a keyboard press reagardless of whether the windows running the program is in focus.
I am running this through the DOS console on a windows 2000 machine.
timetraveldude said:What about just running an application independently of the console window. For example, under unix or linux you can type 'my_prog &' with the '&' sign. If you close the window the program was launched from the program will still run. Is there a way to do this under windows.
thanks for all the help.
#include <ncurses.h>
int main( void )
{
int c ;
initscr() ; // Intialize Screen
raw() ; // Disable Line Buffering
keypad(stdscr, TRUE) ; //Read Function Keys and Arrows
noecho() ; // Disable printing input to screen without permission
printw("Type any character\n") ; // Equivalent to printf
c = getch() ; // Wait for character input
printw("%c was pressed",c) ; // Equivalent to printf
refresh() ; // Print information from stdscr to visible window
getch() ; // Wait for character input
endwin() ; // Destroy Screen
return 0 ;
}
dduardo said:Here is what I suggest. Get cygwin from here: http://www.cygwin.com/
Make sure to install g++. write a program using the ncurses library. Here is some sample code to take ctrl-c, ctrl-d, etc as characters and you can process them as you like:
When you compile this piece of code with g++ make sure to do it this way:
g++ -lncurses <filename.cpp>
dduardo said:Of course the terminal window has to be in focus. How else do you differentiate input between multiple programs
Running a program in the background means that the program is running without being visible on your screen. This allows you to continue using your computer while the program is running.
This can vary depending on your operating system, but typically you can run a program in the background by adding an ampersand (&) at the end of the command when launching the program in the terminal. For example: "python my_program.py &" or "my_program.exe &".
Running a program in the background allows you to multitask and use your computer for other tasks while the program is running. It also allows you to continue using your computer without any disruptions or pauses caused by the program.
Yes, you can run multiple programs in the background at the same time. However, it is important to consider the resources of your computer and make sure it can handle running multiple programs simultaneously.
To stop a program that is running in the background, you can use the "fg" command in the terminal to bring the program to the foreground and then use the appropriate command to stop the program. Alternatively, you can use the "kill" command with the process ID of the program to stop it.