1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

system(someString) causing problems

Discussion in 'iPhone/iPad Programming' started by lynkynpark86, Jan 29, 2011.

  1. macrumors 6502

    #1
    I'm trying to get better at Obj-C, and I'm making a series of simple apps. For developers of cydia apps, I'm sure you've heard of the Erica Utilities. I'm using the urlclip utility to make an app that makes a webclip. Here's my code:
    Code:
    -(IBAction)makeClip {
    	
    	urlString = [[NSString alloc] initWithFormat:urlField.text];
    	nameString = [[NSString alloc] initWithFormat:nameField.text];
    	cmdString = [[NSString alloc] initWithFormat:@"urlclip %@ %@", nameString, urlString];
    	system(cmdString);
    	
    }
    
    But my system(cmdString) line is getting a warning: "Passing argument 1 of 'system' from incompatible pointer type". Is it because I'm using a string within system()? I tested it on my device, and it isn't working. The cmdString string is working right, as I tested it with a UIAlertView. The problem IS in the system(). Any ideas?
     
  2. macrumors 6502a

    #2
    The warning is GCC telling you are trying to call the system function in a way that does not match it's definition (and it is completely correct). system(3) is a function from the Standard C library and expects C (not Objective-C) datatypes. I would suggest opening up a Terminal window and typing:
    Code:
    man system
    and read the function's man page to get some idea about how it's declared, the number of type of it's arguments, etc.
     
  3. macrumors 6502

    #3
    I read the man page, and what I gathered is that I should be using sh(), not system(). I tried sh(), and I am now getting an actual error, not a warning. I guess what I'm saying is, how do I run a string as a command on the iPhone?
     
  4. macrumors 6502a

    #4
    Re-read the man page (specifically the 'Synopsis' section), the function you are using is correct but you are not calling it with the correct arguments. If you are still stuck after that, here's another hint: Take a look at the NSString class reference, one of it's methods will convert the string into the form you need.
     
  5. macrumors 6502

    #5
    Are you talking about const char? I'm assuming it's not int you're talking about. So I need NSStringEncoding? How would I type that? I'm sorry I'm asking you so spell it out for me, but I am very new to programing.
     
  6. macrumors regular

    #6
    I'm pretty sure you're not allowed to use the system(3) call on an iOS device. system(3) uses the fork(2) call, and that call is blocked by Apple.

    But don't take my word for it, last time I tried using it was almost a year ago and things might have changed since then.
     

Share This Page