2016-01-07 57 views
0

我有一個C#程序,將由mono執行。從C#程序中,我想獲得運行該程序的mono vm二進制文件的路徑。有沒有一個API?mono C#獲取正在運行的mono的路徑vm

請注意,我不是要求C#程序的路徑,而是單聲道vm二進制文件的路徑(例如/usr/local/bin/mono)。

+0

對於downvote和close請求:我不是要求一個圖書館,而是一種獲得單聲道的方式。它類似於其他流行的問題,如http://stackoverflow.com/questions/52797/how-do-i-get-the-path-of-the-assembly-the-code-is-in –

+0

是不相關的c#或甚至單聲道,更多的Linux itsef。 命令** type -a mono **爲您提供了單聲道的真實路徑,在shell中輸入命令** ps -ax | grep mono | grep hello **爲你輸出helloworld.exe由單聲道執行(你可以從對象System.Diagnostics.Process獲得相同的結果,將會更多的Windows方式) – vitalygolub

+0

如果我在Windows上使用mono,該怎麼辦?我正在考慮這個C#/ Mono問題的原因是,在其他語言中存在這樣的API。例如在Python中,有['sys.executcutable'](https://docs.python.org/2/library/sys.html#sys.executable)。我正在尋找相當的。 –

回答

2

你可以做MonoDevelop的工作來找到location of Mono。這是基於查找程序集的位置,然後返回四個目錄來查找當前正在使用Mono的前綴。

首次發現包含int的程序集的位置。

string location = typeof (int).Assembly.Location; 

然後你上去四個目錄找到前綴。 MonoDevelop的這是否符合有多達設置爲4

static string PathUp (string path, int up) 
    { 
     if (up == 0) 
      return path; 
     for (int i = path.Length -1; i >= 0; i--) { 
      if (path[i] == Path.DirectorySeparatorChar) { 
       up--; 
       if (up == 0) 
        return path.Substring (0, i); 
      } 
     } 
     return null; 
    } 

string prefix = PathUp (typeof (int).Assembly.Location, 4); 

這會給你的前綴,通常是在/ usr或/ usr /地方,然後你可以追加找到所在的目錄下面的代碼單聲道正在運行。