Thread: Executing program from a Command Line

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    58

    Executing program from a Command Line

    How would i go about executing a program from a command prompt with the input file name and output file name as command line arguments? forexample if my program is named "program" the command i need is >program mycode.c output.txt< it needs to be runnable from a DOS or Linux command line prompt. how woujld i go about doing this? i have no idea

  2. #2
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    short answer: program.exe mycode.c output.txt

    Long answer to follow. . .

    The C standard defines main something like:
    Code:
    int main(int argc, char *argv[])
    The command shell forms up the command and all parameters into an array. Each space creates a new parameter. So, for the example above your argv would be:

    argv[0] = "program.exe"
    argv[1] = "mycode.c"
    argv[2] = "output.txt"

    and argc would be 3.
    Last edited by Kennedy; 05-05-2010 at 01:17 PM. Reason: Provided more info.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 40
    Last Post: 09-01-2006, 12:09 AM
  2. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 07:49 PM
  3. Executing a program
    By trancedeejay in forum C Programming
    Replies: 7
    Last Post: 03-06-2006, 08:55 AM
  4. Problem executing sample program:
    By mrabiu in forum C++ Programming
    Replies: 4
    Last Post: 03-13-2004, 06:44 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM