我有什么,我认为是一个简单的问题。传递用户输入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