how do i get to the system in C++?

Discussion in 'C++' started by Tamer Higazi, Jul 21, 2003.

  1. Tamer Higazi

    Tamer Higazi Guest

    Hi!
    I want to run an external Program in my C++ Program. I have a string of
    an existing program which has to be executed. Which command do i have to
    execute and in which library is it to find?

    For anybody's help, Thank you.


    Tamer
    Tamer Higazi, Jul 21, 2003
    #1
    1. Advertising

  2. > I want to run an external Program in my C++ Program. I have a string of
    > an existing program which has to be executed. Which command do i have to
    > execute and in which library is it to find?


    The std::system() function in <cstdlib>seems to be what you are looking for.

    --
    Peter van Merkerk
    peter.van.merkerk(at)dse.nl
    Peter van Merkerk, Jul 21, 2003
    #2
    1. Advertising

  3. Tamer Higazi

    Tamer Higazi Guest

    Dear Peter,
    How do i run correctly the function?!

    "Fullsting" is a variable of string.



    FullString.assign(StringToConvert[0]);
    FullString.append(StringToConvert[1]);
    FullString.append(StringToConvert[2]);
    system(FullString);

    and output:

    g++ CapiSuitePrint.C
    CapiSuitePrint.C: In member function `void CapiPrint::convert()':
    CapiSuitePrint.C:49: error: cannot convert `std::string' to `const
    char*' for
    argument `1' to `int system(const char*)'
    tamer@linux:~/Desktop/CapiSuitePrint>

    Tell me please, how i could avoid this error.


    Thank you

    Tamer

    Peter van Merkerk wrote:
    >>I want to run an external Program in my C++ Program. I have a string of
    >>an existing program which has to be executed. Which command do i have to
    >>execute and in which library is it to find?

    >
    >
    > The std::system() function in <cstdlib>seems to be what you are looking for.
    >
    > --
    > Peter van Merkerk
    > peter.van.merkerk(at)dse.nl
    >
    >
    Tamer Higazi, Jul 21, 2003
    #3
  4. "Tamer Higazi" <> wrote in message
    news:3f1c5cfc$0$1575$...
    > Dear Peter,
    > How do i run correctly the function?!
    >
    > "Fullsting" is a variable of string.
    >
    > FullString.assign(StringToConvert[0]);
    > FullString.append(StringToConvert[1]);
    > FullString.append(StringToConvert[2]);
    > system(FullString);


    This should work:

    system(FullString.c_str());

    --
    Peter van Merkerk
    peter.van.merkerk(at)dse.nl
    Peter van Merkerk, Jul 21, 2003
    #4
  5. Tamer Higazi

    Rolf Magnus Guest

    Tamer Higazi wrote:

    > Dear Peter,
    > How do i run correctly the function?!
    >
    > "Fullsting" is a variable of string.
    >
    >
    >
    > FullString.assign(StringToConvert[0]);
    > FullString.append(StringToConvert[1]);
    > FullString.append(StringToConvert[2]);


    You could write this a bit cleaner with using operators:

    FullString = StringToConvert[0];
    FullString += StringToConvert[1];
    FullString += StringToConvert[2];

    or even:

    FullString = StringToConvert[0] +
    StringToConvert[1] +
    StringToConvert[2];

    > system(FullString);


    Try:

    system(FullString.c_str());
    Rolf Magnus, Jul 21, 2003
    #5
  6. Tamer Higazi

    Default User Guest

    Tamer Higazi wrote:

    > CapiSuitePrint.C: In member function `void CapiPrint::convert()':
    > CapiSuitePrint.C:49: error: cannot convert `std::string' to `const
    > char*' for
    > argument `1' to `int system(const char*)'
    > tamer@linux:~/Desktop/CapiSuitePrint>



    Well, how do you get a const char* from a std::string? If you don't
    know, look it up in your book. If you don't have a book, get one. If you
    have one and it doesn't say, get a different one.



    Brian Rodenborn
    Default User, Jul 21, 2003
    #6
  7. Tamer Higazi

    Tamer Higazi Guest

    Hi!
    I don't understand why but i still got that problem. I just made a test
    if the string could be executed correctly by just making

    cout << "\n" << FullString;

    and i tested this string manually and it worked.


    StringToConvert[0] = "sfftobmp -t
    /var/spool/capisuite/users/tamer/received/fax-";
    StringToConvert[1] = static_cast<char>(CharNextNo);
    StringToConvert[2] = ".sff
    /var/spool/capisuite/users/tamer/received/ToPrint.tiff";

    FullString.assign(StringToConvert[0]);
    FullString.append(StringToConvert[1]);
    FullString.append(StringToConvert[2]);
    //cout << "\n" << FullString << "\n";
    system(FullString.c_str());


    Output:

    tamer@linux:~/Desktop/CapiSuitePrint> ./a.out
    Error open file.


    I really don't know what to do now.

    Rolf Magnus wrote:
    > Tamer Higazi wrote:
    >
    >
    >>Dear Peter,
    >>How do i run correctly the function?!
    >>
    >>"Fullsting" is a variable of string.
    >>
    >>
    >>
    >>FullString.assign(StringToConvert[0]);
    >>FullString.append(StringToConvert[1]);
    >>FullString.append(StringToConvert[2]);

    >
    >
    > You could write this a bit cleaner with using operators:
    >
    > FullString = StringToConvert[0];
    > FullString += StringToConvert[1];
    > FullString += StringToConvert[2];
    >
    > or even:
    >
    > FullString = StringToConvert[0] +
    > StringToConvert[1] +
    > StringToConvert[2];
    >
    >
    >>system(FullString);

    >
    >
    > Try:
    >
    > system(FullString.c_str());
    >
    Tamer Higazi, Jul 22, 2003
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sfunds sfunds
    Replies:
    9
    Views:
    8,677
  2. Charles A. Lackman

    Streaming with System.IO and System.Net

    Charles A. Lackman, Dec 8, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    535
    Richard Grimes [MVP]
    Jan 15, 2005
  3. Mark Miller
    Replies:
    1
    Views:
    1,061
    Mark Miller
    Jul 18, 2003
  4. Matt
    Replies:
    2
    Views:
    825
    Matt Getting
    Jul 24, 2003
  5. Kelsang Wangchuk

    System.Timers.Timer vs. System.Threading.Timer

    Kelsang Wangchuk, Jul 31, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    702
    Kelsang Wangchuk
    Jul 31, 2003
Loading...

Share This Page