• 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: Incompatible pointer type
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Incompatible pointer type


  • Subject: Re: Incompatible pointer type
  • From: Jens Alfke <email@hidden>
  • Date: Fri, 15 Jan 2010 08:46:52 -0800


On Jan 15, 2010, at 7:23 AM, Gary McGill wrote:

I am trying to pass a variable to system(). The final code would look like this:
system(“lp –d Internal_Modem –o phone=555-5555 ~/Desktop/fileToFax.pdf”)

If I simply put this line in my code, it works fine. The problem is I have to get the phone number from the database. When I build the string using AppendString [...]

Earlier replies have addressed your immediate problem, but I want to recommend that you not call system().

(1) Assembling command-line strings is messy, because you have to deal with issues of shell quoting. In your case, can a phone number contain a "*" or "#"? Either one will confuse the shell and make the command fail. In general this can be a nightmare to deal with. In the worst case, if you don't trust the data source, this can allow hackers to exploit your app to run arbitrary code (e.g. passing in a phone number like "0; rm -rf ~;") — this has been the cause of many, many, many attacks on websites and other systems.

(2) You don't know which shell is going to run the command — probably bash, but some people (like me) use tcsh, and there's also zsh. All have subtle differences in the way they parse commands.

(3) Launching a shell has overhead. Probably not an issue in your case, but if you call this a lot it  can be noticeable.

(4) Why use a Unix system call when there are friendly Cocoa classes that do the same thing?

What you should be using instead is NSTask. It will let you pass the arguments as individual NSStrings (so no C-string conversion or concatenation to do), they don't get run through a shell or otherwise parsed (so no worries about quoting), and it directly launches the binary (so better performance.)

—Jens
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Incompatible pointer type
      • From: Gary McGill <email@hidden>
References: 
 >Incompatible pointer type (From: Gary McGill <email@hidden>)

  • Prev by Date: Re: Incompatible pointer type
  • Next by Date: Sharing a hint re: Your own templates in Xcode
  • Previous by thread: Re: Incompatible pointer type
  • Next by thread: Re: Incompatible pointer type
  • Index(es):
    • Date
    • Thread