Run an .exe file from an c++ application

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rupali12345
    New Member
    • Jun 2007
    • 13

    Run an .exe file from an c++ application

    Hi all,

    How to run one c++ .exe file from another c++ application...
    I used following code...but not working..

    Code:
    #include<iostream.h>
    #include<stdlib.h>
    int main() 
    {
    system("C:\Rupali1\c++ examples\listConcat\Debug\listConcat.exe");
    //system("explorer.exe");
    return i;
    }
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    Originally posted by Rupali12345
    Hi all,

    How to run one c++ .exe file from another c++ application...
    I used following code...but not working..

    Code:
    #include<iostream.h>
    #include<stdlib.h>
    int main() 
    {
    system("C:\Rupali1\c++ examples\listConcat\Debug\listConcat.exe");
    //system("explorer.exe");
    return i;
    }
    I would imagine you are getting issues with the "c++ examples" part of your path. Try renaming the directory to have an underscore, and see if that works. You could also try backwhacking\ the\ space\ that\ is\ in\ there\. (If you couldn't tell, that's putting a slash right before the space - tells the compiler to expect the space. I'm not sure how well that works on Windows machines - I know I've done it several times on Linux machines.)


    ::Edit:: you might also try backwhacking the slashes - that just occurred to me. So, something like: C:\\Documents\ and\ Settings\\Usern ame\\directory\ \file_to_execut e.exe, or some combination of those things.

    Comment

    • niskin
      New Member
      • Apr 2007
      • 109

      #3
      The problem lies in the path of your program:

      system("C:\Rupa li1\c++ examples\listCo ncat\Debug\list Concat.exe");

      This is incorrect as the backslash is used for other things in C and C++ so what you need to do is put 2 of them:

      system("C:\\Rup ali1\\c++ examples\\listC oncat\\Debug\\l istConcat.exe") ;

      Personally, just to be safe I would put:

      system("cd C:\\Rupali1\\c+ + examples\\listC oncat\\Debug & listConcat.exe" );

      Happy programming.

      Comment

      • vpawizard
        New Member
        • Nov 2006
        • 66

        #4
        Hello,
        U can also use exec*() functions.
        http://linux.about.com/library/cmd/blcmdl3_execl.h tm

        Regards,

        Comment

        • Rupali12345
          New Member
          • Jun 2007
          • 13

          #5
          Hi,

          system("cd C:\\Rupali1\\c+ + examples\\listC oncat\\Debug & listConcat.exe" );

          This is working fine........... .....

          Thanks.
          Happy Programming To U also.

          Comment

          Working...