[I posted this at discussions.apple.com, but realise that this is probably a more appropriate venue for a technical question]

I am writing a simple Cocoa-ObjectiveC wrapper around a command-line tool written in C, and understand the basics of using NSTask, NSPipe, NSFileHandle and multiple executable targets. My development platform is Xcode 3 / Leopard.


The Cocoa interface uses an NSTextView to display the stdout (and stderr, if necessary) of the CL tool, and to accept text directed to the tool's stdin. The message appearing in the text view on launching the app is that the data file is not found.


I use a Copy Files build phase in the Xcode project to put the auxiliary executable in the MacOS folder of the app bundle where the app's executable is. The data file is there, but the tool executable is not seeing it when it is being run by NSTask. The tool target has to load a read-only data file on launch or it fails. The tool target builds and executes OK in the Xcode console because it has its own Copy Files build phase to get a copy of the data file.


The tool tries to open the file with an ordinary call to fopen():


f = fopen("my.data",READ_MODE);


In windowDidLoad I've set the path for the auxiliary executable like this:


path = [[ NSBundle mainBundle ] pathForAuxiliaryExecutable: @"BackEnd" ];


backEnd = [[ NSTask alloc ] init ];

//[ backEnd setCurrentDirectoryPath: [ path stringByDeletingLastPathComponent ] ];

[ backEnd setLaunchPath: path ];


Of course, I'm concerned about having had to comment out the setCurrentDirectoryPath operation, which I inserted on the following advice:


http://cocoadev.com/wiki/UsingAuxiliaryExecutableInBundle


There is probably something somewhere in my auxiliary executable code that is not working with the environment it gets as an NSTask. I am puzzled that the standalone tool executable has no trouble the data file located in the same directory from which it launches, and runs fine in the Xcode console. In fact, when I drill into the app bundle and run the tool executable down there, it is fine, of course.


I probably have not sufficiently studied the source code for the auxiliary executable and the mechanics of how NSTask sets up the launch environment for the auxiliary. I was doing a lot of Cocoa programming a few years ago, when the OS was still 10.4, and I am trying to spin up to using 10.5 and 10.6 now, and a lot of things feel different. Any gentle advice will be greatly appreciated.
_______________________________________________

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