Piping the result of a Unix command
Piping the result of a Unix command
- Subject: Piping the result of a Unix command
- From: Lorenzo <email@hidden>
- Date: Fri, 03 Oct 2003 14:06:49 +0200
Hi,
I have just put the unix command "pdftotext" on the root of my boot disk.
Just to try it. Later I will embed the command within my Cocoa application.
Then I launch Terminal, just to try it and if I do:
/pdftotext /000/myFile.pdf -
it works fine, filling the terminal window with the text. Good.
If I replace the dash with a pathname like
/pdftotext /aaa.pdf /bbb.txt
I get a new file /bbb.txt containing that text. Good.
So the unix command works very well.
Now I call it from within my Cocoa application.
I would like to get the text through a pipe.
So I try:
NSArray *args = [NSArray arrayWithObjects:filePath, @"-", nil];
NSTask *task = [[NSTask alloc] init];
NSPipe *thePipe = [NSPipe pipe];
[task setStandardOutput:thePipe];
[task setLaunchPath:@"/pdftotext"];
[task setArguments:args];
[task launch];
[task waitUntilExit];
NSData *dataOut = [[[task standardOutput] fileHandleForReading]
availableData];
and my program freezes.
If I replace the argument dash with a pathname, like
NSArray *args = [NSArray arrayWithObjects:filePath, outFile, nil];
my program works and I get the file outFile with the text properly.
and [dataOut length] is always ZERO.
So I am forced to read the text from the outFile. And I don't want this.
So, how should I get the text without passing by an output file?
I already tried to pipe the standard output with other commands and it
worked. With this command I cannot make it work.
Do you know why?
Best Regards
--
Lorenzo
email: email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.