Thread: command line parameters

  1. #1
    Join Date
    Sep 2001

    command line parameters

    Forgive my question if it's easily answered, but last night I don't think I was quit getting it / figuring it out. Would there be a "good" way to pass 4 command line parameters to a program, then house this in a function so you can change them at will?

    Here's an extremely hackish example as I couldn't figure much else out:
    int ExtractZip( char * SourceFile, char * Destination, char * Name )
    	FILE * Tmp;
    	if( ( Tmp = fopen("Tmp.bat", "a") ) == 0 )
    		/* Nothing */
    		fprintf(Tmp, "@echo off\n");
    		fprintf(Tmp, "d:\\unzip.exe ");
    		fprintf(Tmp, "%s", SourceFile);
    		fprintf(Tmp, " -d ");
    		fprintf(Tmp, "%s >NUL", Destination);
    		printf("Copied:  %s\n", Name);
    	return 0;
    System will obviously not work for this, if it did it would be fine as the intended platform has system, but, system can't accept changable arguments.

    I looked into spawn, but couldn't figure much out.
    Typical command line:
    unzip.exe c:\path\to\ FileIwant.ext -d c:\place\to\put\it
    unzip.exe will remain the constant, the last 4 arguments however need to be changed at will....

    Any suggestions?
    The world is waiting. I must leave you now.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Simple approach
    char buff[1000];
    sprintf( buff, "d:\\unzip.exe %s -d %s >NUL", SourceFile, Destination);
    system( buff );
    Or use spawnv, like so
    char *args[4];
    args[0] = SourceFile;
    args[1] = "-d";
    args[2] = Destination;
    args[3] = NULL;
    spawnv( P_WAIT, "d:\\unzip.exe", args );
    But this doesn't have redirection

  3. #3
    Join Date
    Sep 2001
    Thank you for your suggestions Salem.
    I will toy with those after a bit and post a reply with what I come up with.
    The world is waiting. I must leave you now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Parameters quick Question
    By lifeis2evil in forum C++ Programming
    Replies: 2
    Last Post: 11-18-2007, 11:12 PM
  2. function with variable number of parameters
    By mikahell in forum C++ Programming
    Replies: 3
    Last Post: 07-23-2006, 03:35 PM
  3. Additional parameters for operator delete
    By darksaidin in forum C++ Programming
    Replies: 0
    Last Post: 09-21-2003, 11:46 AM
  4. Passing parameters from VB to C++ through ActiveX DLL
    By torbjorn in forum Windows Programming
    Replies: 0
    Last Post: 12-10-2002, 03:13 AM
  5. command-line parameters.
    By Tombear in forum C Programming
    Replies: 2
    Last Post: 10-28-2001, 08:40 AM