Running Program

Aug 9, 2010 at 4:01pm
I was wondering how to make a program open another program.
Aug 9, 2010 at 4:32pm
exec() or CreateProcess() on Windows.
Aug 9, 2010 at 4:48pm
It didnt Work.
Aug 9, 2010 at 10:48pm
What didn't work?
Aug 10, 2010 at 12:32am
exec() or CreateProcess() on Windows.

Didn't work.
Last edited on Aug 10, 2010 at 12:32am
Aug 10, 2010 at 5:30am
How did it not work?
Aug 10, 2010 at 5:31am
Didn't work.


Better try something else then.
Aug 10, 2010 at 7:49am
can you provide with what code you have written ?
Aug 10, 2010 at 3:16pm
In reply to Zhuge:
It wouldn't open a program.

In reply to firedraco:
I don't know what to try.

In reply to bluecoder:
No because I don't have any programming yet that control the opening of programs and because the code I do have has nothing to do with opening programs.
Aug 10, 2010 at 3:50pm
How do you know it didn't work if you didn't write any code?
Aug 10, 2010 at 5:32pm
well, do the fork and exec the another program in newly created process.

sample code.

int pid = fork()
if(pid==0)
{
exec("your program");
}

execv will overwrite the memory space of newly created process with your program.

Regards.
Aug 15, 2010 at 3:41am
Is there an #include i'm forgeting cause the compiler says it dosent know what exec does.
Last edited on Aug 15, 2010 at 3:41am
Aug 15, 2010 at 5:35am
You must include the process.h header for the exec functions (execl, execv etc). There is documentation for them here (you probably want to look at _execl)
http://msdn.microsoft.com/en-us/library/431x4c1w%28VS.80%29.aspx

Also in process.h are the spawn methods, which can also launch processes (probably want to look at _spawnl)
http://msdn.microsoft.com/en-us/library/20y988d2%28VS.80%29.aspx

Lastly there is the CreateProcess method in the Windows.h header
http://msdn.microsoft.com/en-us/library/ms682425%28VS.85%29.aspx

Give one or a couple of these a try, and if you are having difficulties, post your code and your problem for additional help.
Aug 15, 2010 at 9:06am
If you post the code you have and post what platform you want to run it on, you may make speedier progress.

How To: Ask Questions The Smart Way
http://www.cplusplus.com/forum/articles/1295/
Topic archived. No new replies allowed.