• 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: Passing NSString to system()
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Passing NSString to system()


  • Subject: Re: Passing NSString to system()
  • From: "Finlay Dobbie" <email@hidden>
  • Date: Wed, 4 Oct 2006 18:47:48 +0100

You're missing lots of things, unfortunately.

Firstly, the specifier for C strings is %s, not %.

Secondly, system() does not take a format string, nor is it a variable
argument list function like printf, etc. You'd have to use something
like snprintf to construct a string in memory before handing it off to
system().

Thirdly, you convert NSStrings to C strings by calling, for example,
[myString UTF8String].

Fourthly, there's an Objective-C class for executing commands which is
far more powerful than system() that you probably should be using
instead (and also doesn't necessarily have the overhead of invoking a
new shell). Read about NSTask in the manual.

-- Finlay

On 04/10/06, Aychamo Aychamo <email@hidden> wrote:
I am trying to insert the contents of a NSString into a c-string, to
be used in a system() call.  I am having problems.

I've tried:

system("%", myString);

without success.  I know I must be missing something.

Thank you
AA
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Passing NSString to system() (From: "Aychamo Aychamo" <email@hidden>)

  • Prev by Date: Re: NSImage and F_NOCACHE
  • Next by Date: Re: Passing NSString to system()
  • Previous by thread: Passing NSString to system()
  • Next by thread: Re: Passing NSString to system()
  • Index(es):
    • Date
    • Thread