FROM : Clark S. Cox III
DATE : Thu Jan 17 14:55:30 2002
On Thursday, January 17, 2002, at 06:08 , Markus Hitter wrote:
> Am Donnerstag den, 17. Januar 2002, um 02:01, schrieb Andreas Wolf:
>
>> I ran into weird situations when trying to popen() a path that
>> was retrieved with -(NSString*) pathForResource:ofType because the path
>> name for that resource contains a space character. The shell that gets
>> invoked
>> implicitly interprets the space as a delimiter for the path.
>
> Try to put the name into single or double quotes. Should be easier than
> adding backslashes.
>
> Like:
>
> NSString *path;
> unsigned char *tempStr;
> FILE *myPipe;
>
> ...
>
> sprintf(tempStr, "cat \"%s\"", [path cString]);
> myPipe = popen(tempStr, "r");
> if (myPipe) ...
Instead of [path cString], you should be using [path
fileSystemRepresentation]. If you use cString, and the string contains
characters that can't be represented by the default C-string encoding (i.e.
it contains foreign characters), it will raise an exception.
--
Clark S. Cox, III
<email_removed>
http://www.whereismyhead.com/clark/
DATE : Thu Jan 17 14:55:30 2002
On Thursday, January 17, 2002, at 06:08 , Markus Hitter wrote:
> Am Donnerstag den, 17. Januar 2002, um 02:01, schrieb Andreas Wolf:
>
>> I ran into weird situations when trying to popen() a path that
>> was retrieved with -(NSString*) pathForResource:ofType because the path
>> name for that resource contains a space character. The shell that gets
>> invoked
>> implicitly interprets the space as a delimiter for the path.
>
> Try to put the name into single or double quotes. Should be easier than
> adding backslashes.
>
> Like:
>
> NSString *path;
> unsigned char *tempStr;
> FILE *myPipe;
>
> ...
>
> sprintf(tempStr, "cat \"%s\"", [path cString]);
> myPipe = popen(tempStr, "r");
> if (myPipe) ...
Instead of [path cString], you should be using [path
fileSystemRepresentation]. If you use cString, and the string contains
characters that can't be represented by the default C-string encoding (i.e.
it contains foreign characters), it will raise an exception.
--
Clark S. Cox, III
<email_removed>
http://www.whereismyhead.com/clark/
| Related mails | Author | Date |
|---|---|---|
| Andreas Wolf | Jan 17, 02:01 | |
| Ben Jansen | Jan 17, 02:32 | |
| dave sapone | Jan 17, 11:53 | |
| Markus Hitter | Jan 17, 12:08 | |
| Clark S. Cox III | Jan 17, 14:55 | |
| Douglas Davidson | Jan 17, 18:34 | |
| Malte Tancred | Jan 17, 19:23 | |
| Andrew Pinski | Jan 17, 19:33 | |
| Douglas Davidson | Jan 17, 19:36 | |
| Malte Tancred | Jan 17, 20:17 | |
| Markus Hitter | Jan 17, 21:31 |






Cocoa mail archive

