I'm new to C++ programming. So, which libraries or functions should I use in retrieving this info from the registry? Just give me a brief idea about the steps involved in retrieving the java version number from registry. I'm using VC++.
Asked
Active
Viewed 111 times
0
-
2What have you tried so far? How did (or didn't) that work? Maybe you need to read about [how to ask good questions](http://stackoverflow.com/help/how-to-ask). or how to create a [Minimal, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve)? – Some programmer dude Aug 31 '15 at 12:10
-
Why do you search for the Java version when using C++? What do you want to achieve? – Beachwalker Aug 31 '15 at 12:29
1 Answers
0
If java paths are properly set, you could just run java -version from code: Using the code described here How to execute a command and get output of command within C++ using POSIX? :
#include <string>
#include <iostream>
#include <stdio.h>
std::string exec(char* cmd) {
FILE* pipe = _popen(cmd, "r");
if (!pipe) return "ERROR";
char buffer[128];
std::string result = "";
while(!feof(pipe)) {
if(fgets(buffer, 128, pipe) != NULL)
result += buffer;
}
_pclose(pipe);
return result;
}
using like:
int main(void) {
std::cout << exec("java -version");
return 0;
}
-
You might want to read [Why is “while ( !feof (file) )” always wrong](http://stackoverflow.com/questions/5431941/why-is-while-feof-file-always-wrong). – Some programmer dude Aug 31 '15 at 13:05