Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > how do i get to the system in C++?

Reply
Thread Tools

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

 
 
Tamer Higazi
Guest
Posts: n/a
 
      07-21-2003
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

 
Reply With Quote
 
 
 
 
Peter van Merkerk
Guest
Posts: n/a
 
      07-21-2003
> 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


 
Reply With Quote
 
 
 
 
Tamer Higazi
Guest
Posts: n/a
 
      07-21-2003
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
>
>



 
Reply With Quote
 
Peter van Merkerk
Guest
Posts: n/a
 
      07-21-2003
"Tamer Higazi" <(E-Mail Removed)> wrote in message
news:3f1c5cfc$0$1575$(E-Mail Removed)...
> 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



 
Reply With Quote
 
Rolf Magnus
Guest
Posts: n/a
 
      07-21-2003
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());

 
Reply With Quote
 
Default User
Guest
Posts: n/a
 
      07-21-2003


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
 
Reply With Quote
 
Tamer Higazi
Guest
Posts: n/a
 
      07-21-2003
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());
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
System.Security.SecurityException: Error de solicitud de permiso de tipo System.Net.WebPermission, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089. Luis Esteban Valencia ASP .Net 0 07-14-2005 01:43 PM
Streaming with System.IO and System.Net Charles A. Lackman ASP .Net 4 01-15-2005 08:00 PM
System error 203 The System could not find environment option sfunds sfunds ASP .Net 9 05-06-2004 09:46 AM



Advertisments