2016-01-06 72 views
0

我在桌面上有一個名爲DocToPDF.exe的控制檯應用程序。我需要在Web應用程序的按鈕點擊上運行它。我想出瞭如何運行該應用程序。現在的問題是,控制檯應用程序需要一隻argument.I需要弄清楚傳遞要傳遞的argument.The參數的方法是「3750」這是我的代碼通過使用Web應用程序提供一個參數來運行控制檯應用程序

System.Diagnostics.Process process = new System.Diagnostics.Process(); 
    process.StartInfo.FileName = "cmd"; 
    process.StartInfo.WorkingDirectory = @"C:\Users\itadmin\Desktop\DocToPDF\DocToPDF\DocToPDF\bin\Debug"; 

    process.StartInfo.Arguments= "/c \"" + "DocToPDF.exe" + "\""; 
    process.StartInfo.UseShellExecute = false; 
    process.StartInfo.RedirectStandardInput = true; 
    process.Start(); 

這是我的控制檯應用程序接受使用到Console.ReadLine

Console.Write("Enter Merchant Acct # : "); 
    string strApprId = Console.ReadLine(); 
    strApprId = strApprId.Trim(); 
    Console.WriteLine("Something awesome is being processed......... "); 
+1

的可能的複製[如何參數傳遞給在C#中另一個進程(http://stackoverflow.com/questions/16057063/如何對-p ass-parameters-to-another-process-in-c-sharp) – tnw

+0

你爲什麼要啓動'cmd'並傳遞'DocToPDF.exe'?你不能直接啓動「DocToPDF.exe」嗎?然後傳遞它的參數? –

+2

在.exe後面使用空格,然後傳遞參數。 'process.StartInfo.Arguments =「/ c \」「+」DocToPDF.exe「+」\「」+「3750」;' – Ian

回答

2

可以使用參數

System.Diagnostics.Process pr=new System.Diagnostics.Process(); 
pr.StartInfo.Arguments = "Specify arguments here";    
pr.StartInfo.FileName="Specify.exe file complete path here"; 
pr.Start(); 
+0

謝謝你完美的作品。有沒有辦法顯示控制檯窗口並在後臺運行它。 –

相關問題