• 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: Using NSTask and NSPipe to perform a shell script
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using NSTask and NSPipe to perform a shell script


  • Subject: Re: Using NSTask and NSPipe to perform a shell script
  • From: Keith Blount <email@hidden>
  • Date: Tue, 5 Sep 2006 15:59:57 -0700 (PDT)

Sorry for replying to my own message, but I'm still
trying to get my head around this one. I'm trying to
use NSTask and NSPipe to do the same as:

cat readme.markdown | md2latex.sh > somefile.tex

I've been experimenting with the examples out there,
and this is what I have so far:

- (void)test
{
    NSBundle *bundle = [NSBundle mainBundle];
	NSString *latexPath = [bundle
pathForAuxiliaryExecutable:@"md2latex.sh"];
	//latexPath = [[latex
stringByDeletingLastPathComponent]
stringByAppendingPathComponent:@"cat"];

    NSTask *task = [[NSTask alloc] init];
    [task setLaunchPath:latexPath];
//	[task setCurrentDirectoryPath:[latexPath
stringByDeletingLastPathComponent]];

	NSPipe *readPipe = [NSPipe pipe];
    NSFileHandle *readHandle = [readPipe
fileHandleForReading];

    NSPipe *writePipe = [NSPipe pipe];
    NSFileHandle *writeHandle = [writePipe
fileHandleForWriting];

    [task setStandardInput: writePipe];
    [task setStandardOutput: readPipe];

    [task launch];

    [writeHandle writeData:[NSData
dataWithContentsOfFile:@"/users/keithblount/Markdown/readme.markdown"]];
    [writeHandle closeFile];

    NSMutableData *data = [[NSMutableData alloc]
init];
    NSData *readData;

    while ((readData = [readHandle availableData])
           && [readData length]) {
        [data appendData: readData];
    }

    NSString *outputString;
    outputString = [[NSString alloc]
                         initWithData: data
							 encoding: NSASCIIStringEncoding];

    [task release];
    [data release];
    [outputString autorelease];

	[textView setString:outputString];	// Write the
string to the text view for testing purposes
}

However, when I do this, I get the following error:

/Users/keithblount/Programming/NSTaskShellTest/build/Debug/NSTaskShellTest.app/Contents/MacOS/md2latex.sh:
line 4: MultiMarkdown.pl: command not found
/Users/keithblount/Programming/NSTaskShellTest/build/Debug/NSTaskShellTest.app/Contents/MacOS/md2latex.sh:
line 4: SmartyPants.pl: command not found
warning: failed to load external entity
"xhtml2memoir.xslt"
cannot parse xhtml2memoir.xslt

Note that all of the files that are named as not being
found are contained in the same directory as
md2latex.sh - they are all copied into the Executables
directory in a build phase. I wonder if I need to do
something else to tell the NSTask where to find all
other files that the shell script refers to? Hmm...

Any help or advice much appreciated.

Many thanks in advance,
Keith


--- ORIGINAL MESSAGE ---

Hello,

I have a rather basic RTFM question, but unfortunately
reading the docs and browsing several online tutorials
on this one (for instance at CocoaDevCentral and
borkware) has only left me confused. I have several
shell scripts that I want to run through a Cocoa app.
My program provides support for exporting to several
text formats, and a user has sent me some shell
scripts that will expand the range of possible
formats. Unfortunately, despite being comfortable with
Cocoa, my knowledge of using shell-scripts is rather
poor, so transferring this into a Cocoa app is proving
problematic. I know I need to use NSTask and NSPipe,
but am having difficulties finding the correct way of
doing this for my own script. This is how I would run
my script in terminal:

cat readme.markdown | md2latex.sh > readme.tex

(This just uses a script to convert "readme.markdown"
to a LaTeX file - it uses MultiMarkDown to do so.)

If anyone could give me some pointers on how to get
this working in an NSTask wrapper, I would be _very_
grateful. I have found some basic stuff on getting
using the pipes with NSPipe, but using NSTask along
with "cat" and the ">" output has me baffled.

Sorry if this seems incredibly obvious to many.

Many thanks in advance,
Keith

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
 _______________________________________________
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

  • Follow-Ups:
    • Re: Using NSTask and NSPipe to perform a shell script
      • From: David Emme <email@hidden>
    • Re: Using NSTask and NSPipe to perform a shell script
      • From: Spencer Salazar <email@hidden>
  • Prev by Date: Re: Is it possible that PreferencePane's share "classes name space"?
  • Next by Date: Re: Using NSTask and NSPipe to perform a shell script
  • Previous by thread: Re: Using NSTask and NSPipe to perform a shell script
  • Next by thread: Re: Using NSTask and NSPipe to perform a shell script
  • Index(es):
    • Date
    • Thread