bpy.context.space_data
will give you the current text editor when you click run script, where you can access the text block.
print(bpy.context.space_data.text.filepath)
For an unsaved text block this is empty. For a file dropped onto the text editor or opened by using the Text->Open Text Block
menu item you will still get an empty filepath.
Blender doesn't appear to fill in the filepath property of a text block unless you save the text block to disk, meaning you need to open the text block and then save as to get a filepath. Once it has a filepath you can save, close and re-open the blend file and it will keep the filepath.
__file__
will give you the path to the text block inside the blend file. That is the path of the blend file with the text block name added as if the blend file was a directory. This applies even if the file is saved to disk.
For your own use you can setup the blend file with the script. If you want to share this then you probably want to make it an addon with AddonPreferences
to save the path to the utility. On registration you might search a few possible paths to get the initial setting and have the user set it as needed, or you can tarball the script and utility so that it is next to the addon script when the user installs it.
subprocess.call()
) $\endgroup$