2010-11-19 27 views
2

運行控制檯應用程序與C#參數 - GUI聯播諮詢

我(警告這是一個C#的n00b問題,努力學習一點C#,同時使事情變得更容易爲一個控制檯應用程序我經常跑!)。 「M試圖而不必在參數每次手動鍵入運行控制檯應用程序(consoleapp.exe) - 該命令是通常的這種形式:

C:/consoleapp.exe --username (uname) --password (pass) --inputfile "c:/pathtofile/filename.xml"

使用C#我甚至可以加載了一個Windows資源管理器文件提示,而不是每次都必須手動輸入文件路徑。我會如何去做這件事?我試過snippet at this link。我通過將ApplicationPath替換爲我的cojnsole應用程序的路徑,ApplicationArguments以上述格式顯示的參數來替代它,除了我不確定如何使用VC#GUI工具連接參數,或者將我從原始控制檯應用程序獲得的輸出轉發回去。

+0

'.bat'文件可能會更簡單(http://tips.oncomputers.info/archives2003/0305/2003-may-04.htm)。 – 2010-11-19 09:43:12

+0

是的,但理想情況下,我希望能夠點擊一個按鈕爲'--inputfile'參數加載一個win explorer文件對話框 - 而不是每次都在外部尋找文件路徑的奢侈品 – ina 2010-11-19 09:47:22

+0

我讀過這個問題多了幾倍,我不確定我是否理解正確。 @伊娜 - 你能寫(一步一步地)你在做什麼?如果'consoleapp'是你開發的一個應用程序,從VS開始構建和運行?或者它是你的應用程序從代碼中激發的應用程序? – 2010-11-19 14:26:44

回答

9

這不是對上述問題的回答 - 請參閱上述問題的評論。

項目屬性對話框調試選項卡上,你可以定義命令行參數工作目錄

0

這裏有一些示例代碼,用參數運行控制檯應用程序並處理輸出。

private static Process PrepareTfProcess(string args) 
{ 
    return new Process 
         { 
          StartInfo = 
           { 
            CreateNoWindow = true, 
            FileName = @"consoleapp.exe", 
            Arguments = args, 
            RedirectStandardOutput = true, 
            UseShellExecute = false 
           } 
         }; 

} 

//... 
using (var process = PrepareTfProcess("--param1 --param2")) 
{ 
    while (!process.StandardOutput.EndOfStream) 
    { 
     string str = process.StandardOutput.ReadLine(); 
     // Process output lines here 
    } 
} 
//... 
+0

雖然我不完全確定這是否是您詢問的問題,以及是否有幫助 – Dyppl 2010-11-19 09:54:09

相關問題