The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
how to execute a programme within a programme ?
Discuss how to execute a programme within a programme ? in the C Programming forum on Dev Shed. how to execute a programme within a programme ? C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

March 31st, 2003, 08:18 AM
|
|
Contributing User
|
|
Join Date: Feb 2003
Location: Belgium
Posts: 60
Time spent in forums: < 1 sec
Reputation Power: 11
|
|
|
how to execute a programme within a programme ?
How do I execute a programme within a C programme ?
any good docs articles on this ?
|

March 31st, 2003, 09:17 AM
|
 |
Contributing User
|
|
Join Date: Jan 2003
Location: USA
|
|
Quote:
NAME
system - execute a shell command
SYNOPSIS
#include <stdlib.h>
int system(const char *string);
DESCRIPTION
system() executes a command specified in string by calling
/bin/sh -c string, and returns after the command has been
completed. During execution of the command, SIGCHLD will
be blocked, and SIGINT and SIGQUIT will be ignored.
RETURN VALUE
The value returned is -1 on error (e.g. fork failed), and
the return status of the command otherwise. This latter
return status is in the format specified in wait(2).
Thus, the exit code of the command will be WEXITSTA-
TUS(status). In case /bin/sh could not be executed, the
exit status will be that of a command that does exit(127). |
If you are using a DOS/Windows C compiler, it should also have implemented system(). Just read the help file/documentation on it.
When you use system(), the calling process is still there and can check the status returned by the system() call.
However, if you want to have the called program replace the calling program, then look into the exec* family of functions.
|

March 31st, 2003, 05:34 PM
|
 |
jasondoucette.com
|
|
Join Date: Feb 2003
Location: Canada
Posts: 378

Time spent in forums: 7 h 23 m 8 sec
Reputation Power: 11
|
|
|
I recall reading a few weeks ago that the system command is VERY slow. Be sure to read the documentation like dwise1_aol suggested. I think it provides an alternative.
|

March 31st, 2003, 07:39 PM
|
 |
Contributing User
|
|
Join Date: Jan 2003
Location: USA
|
|
|
The man page on Linux also mentions some gotcha's regarding signals, I think. It didn't apply to what I was doing, so I didn't pay much attention.
And don't just read the documentation, but also write some test code.
|

May 20th, 2003, 05:03 PM
|
|
Registered User
|
|
Join Date: May 2003
Posts: 25
Time spent in forums: 2 h 51 m 4 sec
Reputation Power: 0
|
|
|

May 20th, 2003, 07:57 PM
|
 |
not a fan of fascism (n00b)
|
|
Join Date: Feb 2003
Location: ct
|
|
|
jason i noticed u said system is very slow? what about execve?
|

May 20th, 2003, 08:46 PM
|
 |
Contributing User
|
|
Join Date: Jan 2003
Location: USA
|
|
Quote: Originally posted by infamous41md
jason i noticed u said system is very slow? what about execve? |
In both Windows and Linux, execve would replace the calling program. In Linux we'd couple it with a fork, but Windows doesn't do forks -- there's CreateProcess which works quite differently.
However, Jason_G never replied, so we don't know what OS he's running or whether exec* would work for him or not.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|