C++ insmod

Hi,

I need some help to do a program that execute the insmod command and get the output. I'm doing something like that:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
string insmod = "insmod myModule.ko kernelmodules_tmp");

	FILE *fp;

	fp = popen(insmod.c_str(), "r");
	pclose(fp);

	fp = fopen("kernelmodules_tmp", "r");

	string data;
	char buff[1024];

	if (fp) {
		while ( fgets(buff, 1024, fp) != NULL ) {
			data.append(buff);
		}

		pclose(fp);
	}

	cout << data << endl;


If I got an error, like when module is already registered, the output error is printed in console only, how can I get the output?!

Thanks !!
Resolved,

I redirected th stderr of isnmod to a file..then I read it getting the error.
 
string insmod = "insmod myModule.ko kernelmodules_tmp 2> errorfile");

Topic archived. No new replies allowed.