Thread: Run in background - No console

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    58

    Run in background - No console

    Is there a way to make a program run in the background?

    Because every program i make pop ups the console.

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    I assumed you're running Windows. If so, yes.

  3. #3
    Registered User
    Join Date
    May 2007
    Posts
    58
    Okey i'll look it up.

    So in *nix it isn't possible? :O

  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    *nix systems it's possible, too, but offhand I believe for Windows it can be done if you use CreateProcess() to start a new process. Otherwise, for Windows.... you need to make your program as a "real" Windows program, and not a console program. That way starting it up will start up as a Win32 Windows process that handles its own message loop and such. If you decide you need a console later on, I think you can call AllocConsole() and set the streams so printf() and the like will print to it.

    If this is all too complicated, you can just call FreeConsole() from your Windows console program and it'll ditch the console.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Oh it's a lot easier in Unix/Linux

    myprog &
    Job done.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    but that's from a shell, not an API.

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    In which case, fork() and exec() are your friends.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. console background
    By abyu in forum C++ Programming
    Replies: 3
    Last Post: 11-04-2006, 07:50 PM
  2. Problem w/ console application compadibility
    By DarkMortar in forum C Programming
    Replies: 2
    Last Post: 05-16-2006, 07:13 PM
  3. Detect Close of a background process
    By Schwarzhelm in forum C Programming
    Replies: 1
    Last Post: 11-05-2003, 01:46 AM
  4. forcing a program to run in the background?
    By Geo-Fry in forum Tech Board
    Replies: 4
    Last Post: 10-27-2003, 08:11 PM
  5. Run in background
    By smog890 in forum C Programming
    Replies: 4
    Last Post: 06-09-2002, 02:22 PM