Re: Passing NSString to system()
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