Hi,
I have a C++ program and I was wondering what different ways there was to open another application (such as CALC or notepad) from that C++ program. Thanks
Amish
Hi,
I have a C++ program and I was wondering what different ways there was to open another application (such as CALC or notepad) from that C++ program. Thanks
Amish
In <cstdlib>, you can use the system() function to execute system commands. It takes a char * as a parameter, so you can either put a string literal, or a pointer to the null-terminated string you wanted executed. So, for example, in Windows:
The use of system() is often advised against for several reasons. The main reason is that you don't know the program will be there. If you're running on a different OS, or if you have user that for some reason or another has deleted that program, it will cause problems. Just keep this in mind - system is not forbidden.Code:#include <cstdlib> ... system("notepad"); ...
Thanks for the reply. Would system() allow me to pass command line parameters to the program.
Amish
Yes. It's just the same as if you were typing something in at the command prompt. For example:
Code:system("format a:")
I tired doing
system("calc");
but a command prompt window also opened up in the backgroud and I don't want that to happen. I did a search for system() on google and msdn and nothing came up. You would not happen to know where I could get more information on that.
Amish
Hello,
You can find a good reference about the system() command here: stdlib reference: system(). Or for other guides you can view the following links:
- In-depth look at system()
- In-depth look at system() [Another Mirror]
- Stack Overflow
Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.
> but a command prompt window also opened up in the backgroud
Read the FAQ
It explains the disadvantages of system(), and gives alternative methods for starting processes on various operating systems.
system() is a barely portable catch-all way of starting a new process, but its seldom the most ideal way.
ok I looked at the info on system but it seems that you can't monitor the process after opening it and I still haven't figured out how to make the command prompt not appear in the background.
I have read that process() might do the job. I am looking into that now. If anybody knows about any newbie documentation on process, feel free to post it. Thanks for the help guys
Amish
http://faq.cprogramming.com/cgi-bin/...&id=1043284392
Use CreateProcess
Thanks this was a very interesting page. I did not know that Cprogramming.com contained these kind of information.Originally Posted by Salem
Amish