Thread: Command Line parameters question

  1. #1
    Registered User
    Join Date
    Nov 2003

    Command Line parameters question

    I am making a program where I want the user to enter the location and name of a file and then execute that file continuisly every 30 seconds...For example c:\timer.exe c:\windows\file.exe and I want file.exe to be fp. However the program crashes..any ideas?

    int main(int argc, char *argv[])
      FILE *fp;
      const int x = 10;
      fp = fopen(argv[0],NULL);
    while (x > 0)
         sleep (30000); 
      return 0;

  2. #2
    Registered User sean345's Avatar
    Join Date
    Mar 2002
    If you want to run your program then don't use the file pointer. You would want to do this:
    - Sean
    If cities were built like software is built, the first woodpecker to come along would level civilization.
    Black Frog Studios

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Registered User
    Join Date
    Nov 2003
    thanks sean345...fixed the the prog runs fine.

  5. #5
    Registered User
    Join Date
    May 2002
    You mean you want a file pointer to point to a .exe file? That probably can be done, but why would you try opening the file via a fopen call unless you just plan on reading the file (although that seems kind of pointless). Instead perhaps try using a different call that runs the program instead of opening it for reading? You could use system() but thats a bad idea in most cases, leads to security leaks in your programs.

    I haven't done much work with running other programs but if you do a search on the board I'm sure you could find another call that would run a program. Then just setup a timer that would make this call every so many seconds. That might fix your problems. Also calling system(fp) would definitly not work because your passing it a pointer to not a string, but a file. What you need to do, if your using this method is to get a string (such as file location) and pass that to system() rather then the pointer your trying to pass.

    Hope this helps,

    PS - sorry about the late reply, someone always seems to reply with the answer between me hitting the "Post Reply" button and hitting the "Submit" button. Heh.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 12:14 PM
  2. Question About My Homework Pls Help Me İmmediately
    By jennyyyy in forum C Programming
    Replies: 27
    Last Post: 03-13-2008, 11:40 AM
  3. Parameters quick Question
    By lifeis2evil in forum C++ Programming
    Replies: 2
    Last Post: 11-18-2007, 11:12 PM
  4. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM
  5. Very simple question, problem in my Code.
    By Vber in forum C Programming
    Replies: 7
    Last Post: 11-16-2002, 03:57 PM