Thread: Launching a program with little CPU loss

  1. #1
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005

    Launching a program with little CPU loss

    I already tried this, but I can't get it to work . . . I want to CD to a directory, run a program, and CD back to where I started from. I can't get it to work. Any way I try, my CPU works overtime.

    I can't even get it to work from a batch file, or anything.

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell

    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

  2. #2
    Registered User
    Join Date
    Jul 2005
    Well what your asking, or how to do it, isn't clear. In C code, WinAPI, or batch file, each would be different. Since I'm most familiar with WinAPI I risk posting some code that would be more suited to the windows forum:
    #include <stdio.h>
    #include <stdlib.h>
    #include <windows.h>
    int main(int argc, char *argv[])
      TCHAR szCurrentDirectory[MAX_PATH];
      GetCurrentDirectory(MAX_PATH, szCurrentDirectory);
      ShellExecute(NULL, "open", "CM8KPersonalityEditor.exe", NULL, NULL, SW_SHOWNORMAL);  
      printf("Press 'Enter' to continue . . . ");
      getchar( );
      return 0;
    It seems a wasted of effort to change directories though as a path to the file can be specified.


  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > Any way I try, my CPU works overtime.
    What exactly do you mean (or want for that matter).
    If your program depends only on the CPU, then it will use 100% of it no matter what you do.

    Things you can try are
    - make your program lower it's priority
    - sprinkle the code with some Sleep() calls.
    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. Launching an application from my program
    By tao in forum Windows Programming
    Replies: 6
    Last Post: 07-04-2006, 01:15 PM
  2. Launching a program on startup
    By beanroaster in forum C++ Programming
    Replies: 5
    Last Post: 05-20-2006, 01:21 PM
  3. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 07:49 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM