Must you concatenate strings before using them in commands such as system()?

This is a discussion on Must you concatenate strings before using them in commands such as system()? within the C++ Programming forums, part of the General Programming Boards category; I'm trying to get the effect of 2 char *'s in one, like so: Code: //I have these varibles... char ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    31

    Must you concatenate strings before using them in commands such as system()?

    I'm trying to get the effect of 2 char *'s in one, like so:

    Code:
    //I have these varibles...
    char *exepath="c:\\test\\";
    char *exe="test.exe";
    //and based on them, id like to run this command:
    system("c:\\test\\test.exe");
    //however I'd like to do it based on what values the variables have. Whats the easiest way to do this? I know theres no way in C.

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,452
    use std::string
    Code:
    std::string path("C:\\test\\");
    std::string exe("test.exe");
    std::string fullPath = path+exe;
    system(fullPath.c_str());
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,288
    What do you mean "there's no way in C"? Of course there is!
    All you need is an actual buffer to store the concatenation result in, and "strcat".
    But since this is the C++ forum, go with vart's example.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. system commands
    By darealnash in forum C++ Programming
    Replies: 8
    Last Post: 08-25-2004, 07:20 PM
  2. Invoking system commands... "A better way?"
    By The_Muffin_Man in forum C++ Programming
    Replies: 10
    Last Post: 06-10-2004, 04:57 AM
  3. what can i type into msdn to bring up all the system commands
    By Shadow12345 in forum Windows Programming
    Replies: 10
    Last Post: 12-30-2002, 05:58 PM
  4. Capturing system commands
    By manwhoonlyeats in forum C Programming
    Replies: 2
    Last Post: 12-07-2002, 06:38 PM
  5. menus and strings
    By garycastillo in forum C Programming
    Replies: 3
    Last Post: 04-29-2002, 11:23 AM

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