-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
/*
Merged from https://stackoverflow.com/questions/646241/c-run-a-system-command-and-get-output/646254#646254
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main( int argc, char *argv[] )
{
FILE *pipeStream;
/* Open the command for reading. */
pipeStream = popen("reg query \"HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment\" /v Path", "r");
if (pipeStream == NULL) {
printf("Failed to run command\n" );
exit(1);
}
/* Read the output a line at a time - output it. */
int i = 0;
int i2 = 0;
char line[1035];
char * delimiterCharacter = "%SystemRoot%";
while (fgets(line, sizeof(line), pipeStream) != NULL) {
if (i == 2){
printf("%i. ", i);
char * token = strstr (line, delimiterCharacter);
while( token != NULL ) {
printf( "\n %i %s", i2, token );
token = strstr (NULL, delimiterCharacter);
i2++;
}
}
i++;
}
/* close */
pclose(pipeStream);
return 0;
}
Metadata
Metadata
Assignees
Labels
No labels