Re: NSTask arguments
Re: NSTask arguments
- Subject: Re: NSTask arguments
- From: John Joyce <email@hidden>
- Date: Thu, 21 Feb 2013 09:52:43 +0900
On Feb 21, 2013, at 9:46 AM, Greg Parker <email@hidden> wrote:
> On Feb 20, 2013, at 4:18 PM, email@hidden 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 email@hidden Runtime Wrangler
>
>
Thanks Greg.
That pretty much answers it the way I thought it would be.
The argument for the tool in question does not read standard in (though some of the other args do…) and that is why I asked this.
I will look into the C level approaches available.
At issue is precisely security because this arg expects a file path to a password file (very dumb, but no other option).
It would be great if there were some Cocoa class that could handle this sort of thing with relative safety.
My other option is to create a silly temp file somewhere with precise permissions, but that has its own obvious risk.
This would not be a tool shipped to anyone so I'm not terribly worried, but I prefer to do this as right as possible.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden