On Feb 20, 2013, at 4:18 PM, dangerwillrobinsondan...@gmail.com wrote:
> Is there a way to feed an NSTask argument data when the command line tool in 
> the task expects a file path argument?
> I would like to not actually create a file to use as the argument, but rather 
> send data that would be in said file. 
> Can this be done via NSFileHandle or NSPipe from NSData?

It is possible to send data to a task. For example, you can send data to the 
task's standard input file descriptor by using -[NSTask setStandardInput:]. 
However, this only works if the command line tool is expecting to read from 
standard input. There are conventions to ask a command line tool to read 
standard input instead of a file (for example, setting the file name argument 
to "-"), but you can't force the tool to do so. Check the tool's documentation.

One alternative is to use a Unix named pipe. A named pipe is a pipe - one end 
writes, the other end reads - but it looks like a file in the filesystem and 
can be opened and read or written as if it were a file, as long as the reader 
or writer makes a single pass straight through the file. That means in some 
cases you can create a named pipe and pass that name to the command line tool. 

You would probably have to drop down to the C mkfifo() function to create the 
named pipe; I don't know if any Cocoa classes can create them. There are some 
other complications like preventing security holes (don't use /tmp) and 
cleaning up orphaned pipes if your app crashes or is killed while the pipe is 
open. The internet has examples of those problems and how to solve them.


-- 
Greg Parker     gpar...@apple.com     Runtime Wrangler



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to