We help IT Professionals succeed at work.

Excution of External program

free096 asked
Medium Priority
Last Modified: 2011-09-20
I'm studying Excution of external program. I want a sample code which execute another. The main (Host) application is C++ window program and sub (client) program is based on C or C++. NOT DLL! Processing can be a simple code like 'C=A+B'. Please let me know how process it is. I want to sample! (I know it may bother you if making a sample. ^^, )
Watch Question

Just use CreateProcess()


I said I needed sample which can run. I can not do it though I know CreateProcess() function.

Sorry, you need a sample.

char pathbuf[_MAX_PATH];

strcat(pathbuf, "\\path\\a.exe");
CreateProcess(NULL, pszHomeDir, NULL, NULL, FALSE, CREATE_NEW_PROCESS_GROUP | NORMAL_PRIORITY_CLASS, NULL, NULL, &StartupInfo, &ProcessInformation);

I assume that you are using windows, besides CreateProcess, you can also use WinExec().  Another alternative is to use system(), which is a C runtime function so it is also available on other platforms.  However, on windows, CreateProcess() is better.

On UNIX, you can use fork() and execle() (or execlp, execvp ...).  Well, you mentioned Windows, so forget about this.


Let me know if you have problem using it.


Thanks, faster. But still I don't know How app. can exchange data with Client app. Yea, OS is windows, of course. Would you mind showing me both sample of Client & Host which can exchange data like 'C = A + B'. (input A & B into Host, Client calculate it, and  Host must show the result, C)

I see, you are actually talking about IPC.  There are a lot of ways to do it depending on what kind of messages you need to exchange between the parent and the child.  So could you let me know the type and size of the messages (both direction) and do they exchange information frequently or simply a one time process?


Thanks, faster, again. Actually I have not heard about IPC. So I have no idea. Are there so many kinds of IPC? Hm... ^^, First of all I want to know just SIMPLE calculation, C=A+B. (It's the starting point. ^^;) I think it's one time process: Host send A&B to Client. and Client send the result, C(=A+B) to Host. And interger type is enough. Can you show me the samples of both Host and Client?
Unlock this solution and get a sample of our free trial.
(No credit card required)

Note that the server->child communication is by command line, other simple choices include env variable.  But they can only be one time.  Better and more complex way include using a pipe, using windows message (create a window in child), socket, OLE etc.  Child->parent is done using an exit status, this can only work for integer.  A better and still easy way is to use windows message, I mean to create a window in parent with a fixed window name, then the child can find the window handle and then use WM_COPYDATA or other messages to pass data back.  Pipe, socket, OLE etc give you more control.
What does the ** in front of the argv means?? in
  int main(int argc, char **argv)


Viktor Ivanov

** means a pointer to a list of pointers, that is the standard C stuff


Thanks, faster. Your code has some error to debug. Anyway, it looks pretty good. I'll try it. After this, if I had more question, I would ask you. Could I know your Email address? (If question, I'll notify you.)
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.