• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: path names with spaces
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: path names with spaces


  • Subject: Re: path names with spaces
  • From: "Clark S. Cox III" <email@hidden>
  • Date: Thu, 17 Jan 2002 08:55:30 -0500

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@hidden
http://www.whereismyhead.com/clark/


  • Follow-Ups:
    • Re: path names with spaces
      • From: Douglas Davidson <email@hidden>
References: 
 >Re: path names with spaces (From: Markus Hitter <email@hidden>)

  • Prev by Date: Re: HTMLEdit
  • Next by Date: Re: Looping sound with NSSound
  • Previous by thread: Re: path names with spaces
  • Next by thread: Re: path names with spaces
  • Index(es):
    • Date
    • Thread