2015-10-20 37 views
-3

我需要通過PInvoke在單聲道應用程序中調用此過程。 圖書館的名字請。Linux。哪個DLL包含execv?

+0

我預計這個變化從系統到系統中。我認爲你需要重新考慮你的方法。 –

+0

我的做法很好。 – biv

+1

Linux沒有DLL,它有共享對象。你想要的是標準C庫,'libc.so' –

回答

2

身爲GNU C的件庫是在libc

http://linux.die.net/man/3/execv

using System; 
using System.Runtime.InteropServices; 

namespace posix 
{ 
    class MainClass 
    { 
     [DllImport ("libc", SetLastError=true)] 
     private static extern int system (string exec); 

     [DllImport ("libc", SetLastError=true)] 
     public static extern int execv (string path, string[] argv); 

     public static void Main (string[] args) 
     { 
      Console.WriteLine ("Error:{0}", system ("ls -l")); 
      Console.WriteLine ("Error:{0}", execv ("/usr/bin/vi", new string[] { "/usr/bin/vi" , "foobar.txt" })); 
      // Of course, being execv without failure we never come back... 
      Console.WriteLine ("Should never be displayed"); 
      Console.WriteLine ("Error:{0}", Mono.Unix.Native.Syscall.execv ("/usr/bin/ls", new string[] { "/usr/bin/ls" })); 
     } 
    } 
} 
+0

找到錯誤。您必須複製程序名稱作爲第一個參數,例如:'execv(「nano」,new string [] {「nano」});' – biv

+0

您正確,更新了它,當您從內存中鍵入代碼... S.O。需要內聯C#編譯器/調試器;-) – SushiHangover