how to run some exe file by using standard C++ code?

Discussion in 'C++' started by Pawel_Iks, Sep 19, 2007.

  1. Pawel_Iks

    Pawel_Iks Guest

    I have some program in the executable form (for example notepad.exe in
    windows) and I want to run it in C++ code. How to do it?
     
    Pawel_Iks, Sep 19, 2007
    #1
    1. Advertising

  2. On 2007-09-19 16:19, Pawel_Iks wrote:
    > I have some program in the executable form (for example notepad.exe in
    > windows) and I want to run it in C++ code. How to do it?


    You cannot. Or to be exact, your really should not, the only way to do
    it in standard C++ is to use system(), but using system() is generally a
    bad idea. To run another program you need to use code specific to your
    platform, on both Windows and POSIX systems (UNIX and LINUX) there is a
    family of functions with names starting with exec which can be used. For
    more information please consult a group discussing programming on your
    system: http://www.parashift.com/c -faq-lite/how-to-post.html#faq-5.9

    --
    Erik Wikström
     
    =?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=, Sep 19, 2007
    #2
    1. Advertising

  3. Pawel_Iks

    Pawel_Iks Guest

    On 19 Wrz, 16:32, Erik Wikström <> wrote:
    > On 2007-09-19 16:19, Pawel_Iks wrote:
    >
    > > I have some program in the executable form (for example notepad.exe in
    > > windows) and I want to run it in C++ code. How to do it?

    >
    > You cannot. Or to be exact, your really should not


    your answer is mysterious ... why I should not do it?
     
    Pawel_Iks, Sep 19, 2007
    #3
  4. Pawel_Iks

    duane hebert Guest

    >> > I have some program in the executable form (for example notepad.exe in
    >> > windows) and I want to run it in C++ code. How to do it?

    >>
    >> You cannot. Or to be exact, your really should not


    >your answer is mysterious ... why I should not do it?


    Not sure what he means either. Maybe he's saying that
    you'd be better using a platform specific way (like
    createprocess() on windows or whatever it's called.)

    If you just want to launch the exe, then
    std::system("notepad.exe");

    should do it as long as notepad.exe is in your path
    or you specify the path.

    The thing is, that once you load whatever you want, you'll
    likely want to hook it in some way and that's a different
    story.
     
    duane hebert, Sep 19, 2007
    #4
  5. On 2007-09-19 22:37, duane hebert wrote:
    >>> > I have some program in the executable form (for example notepad.exe in
    >>> > windows) and I want to run it in C++ code. How to do it?
    >>>
    >>> You cannot. Or to be exact, your really should not

    >
    >>your answer is mysterious ... why I should not do it?

    >
    > Not sure what he means either. Maybe he's saying that
    > you'd be better using a platform specific way (like
    > createprocess() on windows or whatever it's called.)


    The problem with system() is that the consequences of using it is not
    well specified in the C standard (which the C++ standard refers to). The
    C standard says that calling system() with a non null-pointer as
    argument will pass "the string pointed to by [the argument] to [the
    system command processor] to be executed in a manner with the
    implementation shall document; this might then cause the program calling
    system to behave in a non-conforming manner or to terminate."

    As to what system returns it says "If the argument is not a null
    pointer, and the system does return, it returns an implementation-
    defined value."

    Notice that it is not guaranteed to return, and this is not just a
    theoretical problem, not long ago sdDirtySox had a problem where he was
    using system() and the program he ran froze and consequently froze his
    program too.

    Further more, usually when you run another program you want to do
    something more than just run the program, you might want to interact
    with it in some way, this is not possible using system().

    --
    Erik Wikström
     
    =?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=, Sep 20, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pawel_Iks
    Replies:
    2
    Views:
    429
    Randy
    Sep 20, 2007
  2. Python Maniac
    Replies:
    24
    Views:
    806
    Matt McCredie
    Sep 23, 2007
  3. Metalone
    Replies:
    5
    Views:
    294
    Thomas Heller
    Oct 19, 2007
  4. Replies:
    9
    Views:
    1,026
    Paddy O'Loughlin
    Feb 27, 2009
  5. daved170

    run exe and create exe

    daved170, Oct 11, 2009, in forum: Python
    Replies:
    3
    Views:
    490
    Benjamin Kaplan
    Oct 11, 2009
Loading...

Share This Page