Strange problem with system call
Thomas Regner
tomte at subdimension.com
Sat Feb 12 18:57:03 GMT 2000
On Sam, 12 Feb 2000, you wrote:
> Hi,
> my programm creates a temporary file /tmp/mytempfile. Before exiting it
> should remove the file. Up to now I did that with
>
> system("rm -v /tmp/mytempfile");
>
> and it worked. As my program grows I thought that I could later want to
> change the name of the tempfile. So I defined a global variable
>
> const string TEMPFILE = "/tmp/mytempfile";
>
> and changed my code to use TEMPFILE everywhere instead of direcly naming
> "/tmp/mytempfile". I also tried to adjust the abovementioned line. I did
> this:
>
> string cmd = "";
>
> ...
>
> cmd = "rm -v " + TEMPFILE;
> system(cmd.data());
>
should be:
system( cmd.c_str() );
as string::data() returns usually not just the current string-contents, but the whole data-segment of that string,
while c_str() returns a correct char* to a \0-terminated string representation.
> For some reasons this doesnt work. Running the program I get these
> errors
>
> sh: -c: line 1: unexpected EOF while looking for matching '"'
> sh: -c: line 2: syntax error: unexpected end of file
>
> Has someone an idea of what's going wrong there?
--
/--------------
| Thomas Regner
| Kaiserstr. 5
| 26122 Oldenburg
| Tel.: +49 441 7775005
| E.: tomte at subdimension.com
|______________________________/
More information about the KDevelop
mailing list