我有什麼,我認爲是一個簡單的問題。傳遞用戶輸入ProcessStartInfo.Arguments
我試圖創建具有用戶輸入的文本框的鹼性web表單,一個按鈕來運行一個進程和一個標籤或文本框以顯示處理的結果。
的訣竅是,我想用戶的輸入被用作在我的代碼「StartInfo.Arguments」屬性的值。
下面是代碼:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Diagnostics;
namespace MyApp
{
public partial class InputTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public void Button1_Click(object sender, EventArgs e)
{
Process MyProcess = null;
string MyProcessOutput = null;
string MyProcessInput = null;
try
{
MyProcess = new Process();
MyProcess.StartInfo.CreateNoWindow = true;
MyProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
MyProcess.StartInfo.FileName = @"C:\Windows\sysWOW64\myapp.exe"; // Command to run
MyProcess.StartInfo.Arguments = ... //Where I would like to put user input
MyProcess.StartInfo.UseShellExecute = false;
MyProcess.StartInfo.RedirectStandardInput = true;
MyProcess.StartInfo.RedirectStandardOutput = true;
MyProcess.Start();
MyProcessOutput = MyProcess.StandardOutput.ReadToEnd();
}
catch (Exception ex)
{
MyProcessOutput = "An error occurred:\r\n" + ex.Message;
}
finally
{
if (MyProcess != null)
MyProcess.Dispose();
}
MyProcessOutput = MyProcessOutput.Replace("\r\n", "<br />\r\n");
myresultsLabel.Text = MyProcessOutput;
}
}
}
這裏的關鍵是這一行:
MyProcess.StartInfo.Arguments = ... //Where I would like to put user input
一個TextBox,userinput或其他方式來獲得數據的任何想法用戶進入那個特定的屬性?
在此先感謝您的幫助!
爲什麼不把一個'ASP:TextBox'在頁面上,給它一個名字(比如'txtArguments'),然後只用'MyProcess.StartInfo.Arguments = txtArguments.Text'來獲取文本呢? – 2013-03-13 19:43:50