Re: Using NSTask and NSPipe to perform a shell script
Re: Using NSTask and NSPipe to perform a shell script
- Subject: Re: Using NSTask and NSPipe to perform a shell script
- From: Spencer Salazar <email@hidden>
- Date: Tue, 5 Sep 2006 19:14:43 -0400
On Sep 5, 2006, at 6:59 PM, Keith Blount wrote:
// [task setCurrentDirectoryPath:[latexPath
stringByDeletingLastPathComponent]];
if you are getting those kinds of errors, you probably dont want to
comment this out.
not knowing much about your shell script, id suggest appending ":"
and then [latexPath stringByDeletingLastPathComponent] to the value
for the environment variable "PATH". That way you can guarantee that
it will find the executables in its own directory. You can do this
using NSTask's environment and setEnvironment.
spencer
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:
40gmail.com
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