How to open a notepad in C++ then still continue using the c++ program even when the notepad is open? I tried system("filename.txt") But I can't continue using the c++ program unless I close the notepad file. is this possible?
Asked
Active
Viewed 1,306 times
1
-
3Not possible portably. Each OS is going to need different code. Looks like Boost has a library for it, as usual, or at least almost in this case, as it's [not quite in there](http://stackoverflow.com/questions/1683665/where-is-boost-process). – chris Mar 18 '15 at 15:53
-
Spawn a thread and open the editor from there. But chances are, once you're looking at `system()` in your C/C++ code, your program is FUBAR anyway. There are only very few meaningful use cases for `system()`, and I have not really come across one yet in the wild. ;-) – DevSolar Mar 18 '15 at 15:57
2 Answers
2
As an alternative, you can use ShellExecute like this:
ShellExecute(NULL, "open", _T("notepad.exe"), NULL, NULL, SW_SHOWNORMAL);

rrirower
- 4,338
- 4
- 27
- 45
0
You didn't write on what OS you're on but on windows you can use
system("start notepad.exe");
for example:
#include <iostream>
int main (void){
system("start notepad.exe");
std::string x;
std::cin>>x;
std::cout<<x;
return 0;
}
the trick is the "start" command rather then just the filename

David Haim
- 25,446
- 3
- 44
- 78
-
-1 for system(). Causes a lot of trouble including potential security vulnerability, unintended behavior and program possibly being recognized as a virus. – Spook Apr 14 '22 at 09:52