Hi All,

I am using system function to decrypt an encrypted file, But it's taking too much of time, as a result of file access

i want to know how to store the output of system( ) function into local variables instead of a file.

Code goes like this.

sprintf(syscommand,"des -D -k %c%c credit0_e credit0",keys,keys[j]);

my professor gave an hint saying we can use pipes(|) to redirect output to local variables. I don't know how to do that please help me

11 Years
Discussion Span
Last Post by Ancient Dragon

Your professor sounds like he's leading you up the garden path - the system() function takes one argument (a const char*) and returns an int, which, in all cases i'm aware of, is purely an indicator for whether or not the call was successful (0 for success, and non-zero for failure). The option of storing the output in a text file sounds like the best one by far.


Its not really all that difficult -- here is an explaination of popen() and and example program. BTW you don't use system() with popen(), but call whatever program you want directly

char syscommand[BUFSIZ];
char inbuf[BUFSIZ];

             sprintf(syscommand,"des -D -k %c%c credit0_e credit0",keys[i],keys[j]);             
             if ((ptr = popen(syscommand, "r")) != NULL)
                     while (fgets(inbuf, BUFSIZ, ptr) != NULL)
                             (void) printf("%s", buf);
                     (void) pclose(ptr);
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.