Issue with NSTask (probably very simple)

Discussion in 'Mac Programming' started by uberamd, Apr 11, 2010.

  1. uberamd macrumors 68030

    uberamd

    Joined:
    May 26, 2009
    Location:
    Minnesota
    #1
    I am writing a GUI application that calls the command line utility /usr/bin/xmllint. I am going to grab the output from the command and display it, however I am having issues getting it to even execute properly. Here is my code chunk:

    Code:
    -(IBAction)validateButtonClicked:(id)sender
    {
    	NSString* xsdValue = [xsdPathBar stringValue];
    	NSString* xmlValue = [xmlPathBar stringValue];
    	if( [xsdValue isEqualToString:@""] || [xmlValue isEqualToString:@""] )
    	{
    		[outBox setStringValue:@"You must select both an XML file and XSD file"];
    	} else {
    		
    		NSString* xmllintArgs = [NSString stringWithFormat:@"--noout --schema %@ %@", xsdValue, xmlValue];
    		NSLog(@"%@", xmllintArgs);
    		
    		NSTask *xmllint;
    		xmllint = [[NSTask alloc] init];
    		[xmllint setLaunchPath:@"/usr/bin/xmllint"];
    		[xmllint setArguments:[NSArray arrayWithObjects:(NSString*)xmllintArgs, NULL]];
    		[xmllint launch];
    				
    		[xmllint release];
    		xmllint = nil;
    		
    		[outBox setStringValue:@"OK!"];
    	}
    }
    
    Here is the console output:

    However when I copy and paste the EXACT same command in terminal it works perfectly:

    Can anyone diagnose what may be wrong with my code that is causing it to fail on me?
     
  2. JoshDC macrumors regular

    Joined:
    Apr 8, 2009
    #2
    Each argument has to be a separate object in the NSArray, that is the arguments should be [NSArray arrayWithObjects:mad:"--noout", @"--schema", xsdValue, xmlValue, nil];
     
  3. uberamd thread starter macrumors 68030

    uberamd

    Joined:
    May 26, 2009
    Location:
    Minnesota
    #3
    That works perfectly, thank you! Makes sense now that I think about it. I am almost done with this but I am having one more issue with the UI.

    I have a NSTextField (outBox) inside of a NSScrollView. I set the contents of the outBox to the output string, however that allows the scroll view to horizontal scroll. Is there any way to restrict the ScrollView from horizontally scrolling? I would like it to instead wrap the text and just vertically scroll.

    Currently my code is:

    Code:
    [outBox setStringValue:output];
    [outBox sizeToFit];
    
    I understand why it is doing the HZ scroll, because I am calling sizeToFit, but I cant figure out any other way to make the outBox NSTextField only vertically resize and wrap text. Any help would be appreciated.
     
  4. jared_kipe macrumors 68030

    jared_kipe

    Joined:
    Dec 8, 2003
    Location:
    Seattle
    #4
    I'm unfamiliar with the NSTextField but in UITextFields in interface builder, you select the text box and in the properties there are checkboxes for Horizontal scroll, Vertical scroll, scroll enabled... I just set them to have vertical scroll and scroll enabled. Then when I paste in long lines they just wrap to the next line.
     

Share This Page