how to make utilize of system( ) function

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2006
Posts: 1
Reputation: pavanpalaksha is an unknown quantity at this point 
Solved Threads: 0
pavanpalaksha pavanpalaksha is offline Offline
Newbie Poster

how to make utilize of system( ) function

 
1
  #1
Sep 7th, 2006
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[i],keys[j]);
ret1=system(syscommand);

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
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 489
Reputation: Bench has a spectacular aura about Bench has a spectacular aura about Bench has a spectacular aura about 
Solved Threads: 49
Bench's Avatar
Bench Bench is offline Offline
Posting Pro in Training

Re: how to make utilize of system( ) function

 
1
  #2
Sep 7th, 2006
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.
Last edited by Bench; Sep 7th, 2006 at 8:45 pm.
¿umop apisdn upside down?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,454
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1476
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: how to make utilize of system( ) function

 
0
  #3
Sep 7th, 2006
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
  1. char syscommand[BUFSIZ];
  2. char inbuf[BUFSIZ];
  3.  
  4. sprintf(syscommand,"des -D -k %c%c credit0_e credit0",keys[i],keys[j]);
  5. if ((ptr = popen(syscommand, "r")) != NULL)
  6. while (fgets(inbuf, BUFSIZ, ptr) != NULL)
  7. (void) printf("%s", buf);
  8. (void) pclose(ptr);
Last edited by Ancient Dragon; Sep 7th, 2006 at 11:35 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC