problem with system() function...

Reply

Join Date: Jul 2006
Posts: 647
Reputation: jaepi is an unknown quantity at this point 
Solved Threads: 4
jaepi's Avatar
jaepi jaepi is offline Offline
Practically a Master Poster

problem with system() function...

 
0
  #1
May 10th, 2007
hello there, im having trouble with the system() function...as much as possible, i would like my program to be dynamic...i created a program that will make an iso file...it will ask the user to input the directory that he would like to compress...the problem is, how do i append this to the system() function...here is my code...
  1. _________________________________________
  2.  
  3. #include <stdlib.h>
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. const char *directory;
  10.  
  11. int main(){
  12.  
  13. cout << "enter directory name: ";
  14. cin >> directory;
  15. system("ls -l");
  16. system("mkdir"+directory);
  17. system("mkisofs -J -o filename.iso "+directory);
  18.  
  19. return 0;
  20.  
  21. }
  22. ______________________________________________
notice the + directory?? lol...it's obviously wrong...help pls...
Last edited by WaltP; May 10th, 2007 at 1:30 am. Reason: Added CODE tags -- you actually typed right over how to use them when you entered this post...
Retreat!!!
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,021
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 137
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is online now Online
Super Senior Demiposter

Re: problem with system() function...

 
0
  #2
May 10th, 2007
The easiest way is to make a C++ string and use its concatenation operator (which happens to be the plus operator). Use the c_str method to get the C-style string that's similar to the C++ string you've concatenated that the system function needs.

  1. #include <stdlib.h>
  2. #include <iostream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7.  
  8. int main(){
  9.  
  10. string directory;
  11.  
  12. cout << "enter directory name: ";
  13. cin >> directory;
  14. system("ls -l");
  15. system(("mkdir " + directory).c_str());
  16. system(("mkisofs -J -o filename.iso " + directory).c_str());
  17.  
  18. return 0;
  19.  
  20. }
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,009
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 172
Aia's Avatar
Aia Aia is offline Offline
Postaholic

Re: problem with system() function...

 
0
  #3
May 10th, 2007
If all that you are going to do is to use C++ to
make calls to commands to the CLI , why don't
you just make a script in bash with those commands?.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 647
Reputation: jaepi is an unknown quantity at this point 
Solved Threads: 4
jaepi's Avatar
jaepi jaepi is offline Offline
Practically a Master Poster

Re: problem with system() function...

 
0
  #4
May 10th, 2007
Originally Posted by Aia View Post
If all that you are going to do is to use C++ to
make calls to commands to the CLI , why don't
you just make a script in bash with those commands?.
im going to make this as a function to my other c++ program...i was just testing it...
Retreat!!!
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