DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   problem with system() function... (http://www.daniweb.com/forums/thread77878.html)

jaepi May 10th, 2007 12:11 am
problem with system() function...
 
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...
_________________________________________

#include <stdlib.h>
#include <iostream>

using namespace std;


const char *directory;

int main(){

        cout << "enter directory name: ";
        cin >> directory;
        system("ls -l");
        system("mkdir"+directory);
        system("mkisofs -J -o filename.iso "+directory);

return 0;

}
______________________________________________
notice the + directory?? lol...it's obviously wrong...help pls...

Rashakil Fol May 10th, 2007 1:18 am
Re: problem with system() function...
 
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.

#include <stdlib.h>
#include <iostream>
#include <string>

using namespace std;


int main(){

  string directory;

  cout << "enter directory name: ";
  cin >> directory;
  system("ls -l");
  system(("mkdir " + directory).c_str());
  system(("mkisofs -J -o filename.iso " + directory).c_str());

  return 0;

}

Aia May 10th, 2007 1:19 am
Re: problem with system() function...
 
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?.

jaepi May 10th, 2007 2:18 am
Re: problem with system() function...
 
Quote:

Originally Posted by Aia (Post 363451)
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... :D


All times are GMT -4. The time now is 11:20 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC