470,614 Members | 1,556 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,614 developers. It's quick & easy.

Alternative to "system()" in C++

Hey, does anyone know an alternative function in C++ that can execute window programs other then using "system()"?

Thanks
May 3 '07 #1
13 8657
Banfa
9,065 Expert Mod 8TB
CreateProcess
May 3 '07 #2
JosAH
11,448 Expert 8TB
The "exec*" family of functions can be an alternative too.

kind regards,

Jos
May 3 '07 #3
Savage
1,764 Expert 1GB
The "exec*" family of functions can be an alternative too.

kind regards,

Jos
or spawn*

:)

Savage
May 3 '07 #4
CreateProcess
Thanks, I a actually looking for console base functions. A function I can include in my C++ program, and when execute, my C++ program would open up a program from the current window, such as notepad, ie, etc.
May 4 '07 #5
The "exec*" family of functions can be an alternative too.

kind regards,

Jos
I can seem to find any reference on it.
May 4 '07 #6
cpg
1
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <process.h>
  4. #include <windows.h>
  5.  
  6. #define Error(err) printf("error on %s: %d\n",#err,GetLastError());
  7.  
  8. int main(void)
  9. {
  10.     char *ARG[]={"command",0};
  11.  
  12.     //execl("c:\\windows\\notepad","notepad","\"c:\\test.txt\"",0);
  13.     //execv("c:\\windows\\command.com",ARG);
  14.     spawnl(0,"c:\\windows\\command.com","command",0);
  15.     spawnv(0,"c:\\windows\\command.com",ARG);
  16.     printf("etc....\n");
  17.  
  18.     return 0;
  19. }
  20.  
May 4 '07 #7
Banfa
9,065 Expert Mod 8TB
Thanks, I a actually looking for console base functions. A function I can include in my C++ program, and when execute, my C++ program would open up a program from the current window, such as notepad, ie, etc.
That's fine you can call Createprocess from a console based function.
May 4 '07 #8
Banfa
9,065 Expert Mod 8TB
or spawn*
Unfortunately that doesn't exist on Windows.


For that matter I don't think "exec*" does either.
May 4 '07 #9
Savage
1,764 Expert 1GB
Unfortunately that doesn't exist on Windows.


For that matter I don't think "exec*" does either.
That's no prob.It can execute windows applications.

I tested it!

Savage
May 4 '07 #10
Banfa
9,065 Expert Mod 8TB
That's no prob.It can execute windows applications.
Your meaning is not clear to me.

Do you mean

1. That other platforms (Linux I assume) can run native Windows apps and in that environment you can use exec* and spawn* to start applications?

2. Some development platform for Windows (not DevStudio) has library support for exec* and spawn* which can start Windows apps?

3. Something else?
May 4 '07 #11
Savage
1,764 Expert 1GB
Your meaning is not clear to me.

Do you mean

1. That other platforms (Linux I assume) can run native Windows apps and in that environment you can use exec* and spawn* to start applications?

2. Some development platform for Windows (not DevStudio) has library support for exec* and spawn* which can start Windows apps?

3. Something else?
I was saying that by using exec* or spawn* OP can run all possible apps under Windows.Under Linux i'm not sure that OP can run windows app becasue they don't exist on it(or even if they do,they don't have same location or same name).But it can surely run some Unix based apps.


Now it's all up to the OP to select!

Especialy with usage of spawn* user, or in this case our OP, can specify
mode for executing that app which puts spawn* more modular then exec*, I assume

Savage
May 4 '07 #12
Banfa
9,065 Expert Mod 8TB
I was saying that by using exec* or spawn* OP can run all possible apps under Windows.
But exec* and spawn* are not standard library functions and are not part of the WIN32 API (i.e. Windows) so which library/platform are you using / talking about?
OK that is what I was going to reply before I remembered that Windows is POSIX compliant.

However having looked up a little information n Windows POSIX implementation it appears that a POSIX compliant app requires 2 extra processes running to provide it with the POSIX interface required when running on Windows.

This suggests to me that it may not necessarily be the best way to write an app destined solely for Windows. I think I would only be inclined to use it for an app that actually required POSIX compatibility, rather than using it in general. However I can see that for someone already familiar with POSIX and unfamiliar with WIN32 that it may well be easier to just use what they already know.
May 4 '07 #13
Savage
1,764 Expert 1GB
OK that is what I was going to reply before I remembered that Windows is POSIX compliant.

However having looked up a little information n Windows POSIX implementation it appears that a POSIX compliant app requires 2 extra processes running to provide it with the POSIX interface required when running on Windows.

This suggests to me that it may not necessarily be the best way to write an app destined solely for Windows. I think I would only be inclined to use it for an app that actually required POSIX compatibility, rather than using it in general. However I can see that for someone already familiar with POSIX and unfamiliar with WIN32 that it may well be easier to just use what they already know.
OK,I agree with u!

Savage
May 4 '07 #14

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by msigwald | last post: by
8 posts views Thread by Henrik | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.