help with system commands

hello all,
i was hopeing i could get some help with running a windows system command and getting the output of that command returned into a string.
string szMyString = runCommand("dir");
or something like that i no you can use
System("dir");
to get the directory output but all it does is output to the console,
is there anyway to output to a string?
I am pretty sure you can put the data it gives you into a file, and then get the data from the file, but I don't think you can just pipe it into a string.
@tweak
there is nothing imposible in programming;)
ahead, save the result of dir command to a file, and you can read the file as how as you want
 
system("dir >a.txt");
Last edited on
@tweak
U can use _popen for the same.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
	FILE* fp = _popen("dir","rt");

	if(fp != NULL)
	{
		string responseString;
		char a[100];

		while(!feof(fp))
			if(fgets(a, 100, fp) != 0)
				responseString += a;

		cout<<responseString<<endl;
	}

	_pclose(fp);
Topic archived. No new replies allowed.