start a program with space in the path

This is a discussion on start a program with space in the path within the C Programming forums, part of the General Programming Boards category; How do I start a program from a C program whose path is has a space in it? For example, ...

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    3

    start a program with space in the path

    How do I start a program from a C program whose path is has a space in it?

    For example, lots of applications are installed in C:\Program Files\...,

    I've tried "system()", but it thinks "C:\Program" is the command name,

    The "spawn" functions don't like the space in the path either.

    Thanks,

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Perhaps they don't like the \P?

    Post your code.

    Use forward slashes in string literals if you prefer, otherwise escape a backslash with a backslash.

    Enclose the whole string within double-quotes (which each may need to be escaped if used in a string literal).
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Dec 2006
    Posts
    3
    The line is: _spawnl(_P_WAIT, CL, CL, buffer, NULL);

    If CL is "c:\devstudio\vc98\bin\cl.exe", the spawnl() works. (VC is not installed in the default directory.)

    If CL is "c:\Program Files\Microsoft Visual Studio\VC98\bin\cl.exe", then spawnl() won't work.

    The "buffer" contains the rest of the parameters.

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Actual code really does help.

    But does this work?
    Code:
    ""c:\Program Files\Microsoft Visual Studio\VC98\bin\cl.exe""
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Registered User
    Join Date
    Dec 2006
    Posts
    3

    Unhappy

    nope. :-(

    Tried it before I posted.

  6. #6
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    Use "" only for argv[0]. Following is working:
    Code:
    int main(int arc, char* argv[])
    {
    	char CL[] = "d:\\1 1\\N.EXE";
    	char CL2[] = "\"d:\\1 1\\N.EXE\"";
    	 _spawnl(_P_WAIT, CL, CL2, 0);
    	 return 0;
    }
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    For system() Dave_Sinklula's solution should work, though.
    Code:
    system("\"\\program files\\mozilla firefox\\firefox\"");
    Alternatively, use the DOS name for the folder.
    Code:
    system("\\progra~1\\mozill~1\\firefox");
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 08:35 AM
  2. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 10:17 PM
  3. a space in a program path
    By eam in forum C Programming
    Replies: 2
    Last Post: 10-26-2003, 09:19 PM
  4. Start up program
    By Breetai in forum Windows Programming
    Replies: 2
    Last Post: 01-11-2003, 12:12 PM
  5. Start a program
    By FunkeeMunkee in forum C++ Programming
    Replies: 1
    Last Post: 08-26-2001, 07:18 PM

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