[Mono-dev] How to determine the executable directory in a mkbundle-packaged app?

Robert Jordan robertj at gmx.net
Tue Nov 15 05:09:06 EST 2011


On 15.11.2011 07:13, Deniska wrote:
> So the question is: how can I determine the _real_ location of a
> mkbundle-packaged app during runtime? Is there are a way? If no - why?

You may want to get this info from the "proc" file system:


using System;
using System.Text;
using Mono.Unix.Native;

class Test
{
	static void Main ()
	{
		Console.WriteLine (
			BundleEnvironment.GetExecutablePath ());
	}
}

static class BundleEnvironment
{
	public static string GetExecutablePath ()
	{
		var builder = new StringBuilder (8192);
		if (Syscall.readlink("/proc/self/exe", builder) >= 0)
			return builder.ToString ();
		else
			return null;
	}
}

Robert



More information about the Mono-devel-list mailing list