I'm writing a program in C++ and at one point I want to open a file with a certain program (either Libreoffice or Word, depending on what is installed on the pc). For that I need to check which program is installed on the pc first.
I'm usually using linux and for that I have found
if (!system("which libreoffice --writer > /dev/null 2>&1")) {
const char* command = "libreoffice --writer myfile.rtf &";
system(command);
}
which works perfectly.
However, I cannot figure out how to do the same for Windows (the program is meant to run on a Windows pc).
I know that I can query if a program is installed in Windows using where -command, however apparently I don't quite understand how to use it for I cannot get it to work for me.
Help would be very appreciated.
system("which libreoffice --writer > /dev/null 2>&1")assumes the program is accessible through the system path. You can't always count on this, and you definitely can't with Windows.