Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > how to run some exe file by using standard C++ code?

Reply
Thread Tools

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

 
 
Pawel_Iks
Guest
Posts: n/a
 
      09-19-2007
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?

 
Reply With Quote
 
 
 
 
=?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=
Guest
Posts: n/a
 
      09-19-2007
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-lit...t.html#faq-5.9

--
Erik Wikstr├Âm
 
Reply With Quote
 
 
 
 
Pawel_Iks
Guest
Posts: n/a
 
      09-19-2007
On 19 Wrz, 16:32, Erik Wikstr÷m <(E-Mail Removed)> 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?

 
Reply With Quote
 
duane hebert
Guest
Posts: n/a
 
      09-19-2007
>> > 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.


 
Reply With Quote
 
=?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=
Guest
Posts: n/a
 
      09-20-2007
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
run exe and create exe daved170 Python 3 10-11-2009 07:03 PM
Run a python script as an exe and run a new process from it venutaurus539@gmail.com Python 9 02-27-2009 05:22 PM
Is there a way to tell if a script has been run by Pythonw.exe instead of Python.exe? Metalone Python 5 10-19-2007 08:25 PM
how to run some exe file by using standard C++ code? Pawel_Iks C++ 2 09-20-2007 08:01 PM



Advertisments