Running a binary file

Hi all

Is there a way to run a binary shell file from within an a cocoa app? I am familiar with executing files using NSTask and NSNotifications.

My second option will be to copy these files to the /tmp folder then execute an NSTask based-handler. this ail be something like:

set theFiles to current application’s NSBundle’s mainBundle()
set filesToCopy to theFile’s pathForResource:ofType:

your help will be appreciate

Regards,
t.

I’m not sure I follow the question. If you are familiar with NSTask, why not use it (in AppleScriptObjC)?

Hi Shane,

Perhaps I wasn’t clear in my post. My question is can I run a binary file which I will copy into the project using NSTask. The reason is I need to use notification to display the output in a textView. Hope this helps.

Regards,
t.

I’m still not 100% sure what you mean, but if you’re asking if you can include a binary in your app’s bundle and run it form there via NSTask, the answer is yes.

Are you calling terminationStatus()? It’s hard to suggest much else without seeing any code.

When you’re doing it synchronously, you need to call waitUntilExit() on the task before you can call terminationStatus().

Your last couple of messages seem to have disappeared, but your “set theResult to…” statement should be moved to after the waitUntilExit(), and probably to after you have checked that terminationStatus() is OK.

Shane my apologies, Safari went into the spinning ball and I tried to get out and I clicked every where. Not sure why this happened. I will post the code today.

The script works all now and I am able to get the return code. Thank you.

Shane, this app brought up another challenge and that is how to protect adobe’s prov.xml license file that is contained in the app bundle. Is there a way to make it inaccessible since I will distribute the app to all departments on campus. I thought of encrypting the file but don’t know how. Does Cocoa have its own way of accomplishing this?

Regards,
t.

Here is the script.

on runApp:sender
	
	set theBundle to current application's NSBundle's mainBundle()
	set file1 to theBundle's pathForResource:"adobe_prtk" ofType:""
	set file2 to theBundle's pathForResource:"prov" ofType:".xml"
	
	set outPipe to current application's NSPipe's pipe()
	set outFileHandle to outPipe's fileHandleForReading()
	
	set theTask to current application's NSTask's alloc()'s init()
	tell theTask
		setLaunchPath_(file1)
		setArguments_({"--tool=VolumeSerialize", "--provfile=" & file2})
		setStandardOutput_(outPipe)
		|launch|()
	end tell
	
	set theData to outFileHandle's readDataToEndOfFile()
	set theResult to current application's NSString's alloc()'s initWithData:theData encoding:(current application's NSUTF8StringEncoding)
	
	theTask's waitUntilExit()
	set newResult to theResult
	log theResult
	
	if theTask's terminationStatus() as integer is 0 then
		set theResult to "Failed."
		log theResult
	else
		set theResult to "success"
		log theResult
	end if
end runApp:

I’m pretty sure all the encryption stuff is C-based, so you’re going to have to include it in an Objective-C class.

Hi Shane

Your example of NSNotification Center in your book made it possible to get the app to run as I had intended.

Thank you.
t.

I’m glad to hear you got it working.