Launching a program with little CPU loss

This is a discussion on Launching a program with little CPU loss within the C Programming forums, part of the General Programming Boards category; I already tried this, but I can't get it to work . . . I want to CD to a ...

  1. #1
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048

    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.
    dwk

    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: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  2. #2
    Registered User
    Join Date
    Jul 2005
    Posts
    69
    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:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    #include <windows.h>
    
    int main(int argc, char *argv[])
    {
      TCHAR szCurrentDirectory[MAX_PATH];
      
      GetCurrentDirectory(MAX_PATH, szCurrentDirectory);
      SetCurrentDirectory("e:\\projects\\old\\cm8kpersonedit\\release");  
      ShellExecute(NULL, "open", "CM8KPersonalityEditor.exe", NULL, NULL, SW_SHOWNORMAL);  
      SetCurrentDirectory(szCurrentDirectory);
      
      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.

    Regards,
    Brian

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 02:15 PM
  2. Launching a program on startup
    By beanroaster in forum C++ Programming
    Replies: 5
    Last Post: 05-20-2006, 02: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, 11:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21