2012-06-07 18 views
0

我正在研究Linux環境並使用Mono進行開發。我有一個C#項目,我想在其中啓動另一個應用程序/可執行文件。代碼片段如下:異常:System.ComponentModel.Win32Exception:無效的數據在System.Diagnostics.Process.Start_shell

string pathToDB = @"""/root/somefolder/anotherfolder/"""; 
         Process process = new Process(); 
         process.StartInfo.FileName = @"/root/somefolder/filename"; 
         process.StartInfo.Arguments = @"""" + pathToDB + @"""" + "$" + contents + "$" + "documentTerms"; 
         process.Start();  

我傳遞三(3)參數。第一個是文件夾路徑,第二個是我用字符串內容表示的一些文本數據,第三個是一些硬編碼文本。當我運行這個程序,它給了我以下例外/錯誤:

CreateProcess: Unfinished quote. 

Exception: System.ComponentModel.Win32Exception: Invalid data 
at System.Diagnostics.Process.Start_shell (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process) [0x00000] in <filename unknown>:0 
    at System.Diagnostics.Process.Start_common (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process) [0x00000] in <filename unknown>:0 
    at System.Diagnostics.Process.Start() [0x00000] in <filename unknown>:0 
    at (wrapper remoting-invoke-with-check) System.Diagnostics.Process:Start() 
    at XapianTest.SimpleIndex.ProcessFiles (System.String path) [0x000dc] in /root/Projects/XapianTest/XapianTest/SimpleIndex.cs:84 
    at XapianTest.SimpleIndex.ProcessFiles (System.String path) [0x0013d] in /root/Projects/XapianTest/XapianTest/SimpleIndex.cs:105 
    at XapianTest.SimpleIndex.ProcessFiles (System.String path) [0x0013d] in /root/Projects/XapianTest/XapianTest/SimpleIndex.cs:105 
    at XapianTest.SimpleIndex.Main (System.String[] argv) [0x00023] in /root/Projects/XapianTest/XapianTest/SimpleIndex.cs:51  

我在做什麼錯了! 請誰能幫我...

在此先感謝...

回答

0

您需要的參數之間的空格。試試這個:

process.StartInfo.Arguments = @"""" + pathToDB + @""" ""$" + contents + @"$"" " + "documentTerms"; 
+0

感謝您的建議。我試過這個,但它給了我以下例外:'
''xdg-open:unexpected argument'/ root/xapian/quickstart/proverbs /' 嘗試'xdg-open --help'以獲取更多信息。' –

+0

/root/xapian/quickstart/proverbs /是一個目錄,而不是可執行文件,這就是你得到錯誤的原因。 –