system("")

I was wondering, is there ANY safe place to use system("")?
I am wanting to detect the OS version in a Windows system, and here's the code I'm using:
1
2
3
4
5
6
7
8
#include <iostream>

int main() {
    std::cout<<"Your PC is running under ";
    system("echo %OS%.");
    std::cin.get();
    return 0;
}

It's only going to be used on Windows.

There's also 1 more:
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
using namespace std;

int main() {
    cout<<"Press enter to see your PC info."<<endl;
    cin.get();
    cout<<endl;
    system("set");
    cin.get();
    return 0;
}

I'm also using it w/ Windows, just to show the PC info.

Are these safe?
Last edited on
Use GetVersionEx [http://msdn.microsoft.com/en-us/library/ms724451%28VS.85%29.aspx].

Don't use system, it's bad luck.
closed account (S6k9GNh0)
Functions like above are usable all over to replace the original commands or are even used in the original commands (or at least I would think).
Topic archived. No new replies allowed.