C#process.start参数

时间:2017-01-09 20:46:16

标签: c# parameters process.start

我们可以创建.exe文件的快捷方式。

如您所知,快捷方式文件可以包含参数

我想构建一个使用C #代码自动分配参数的程序。

这是我的代码:

    private void button4_Click(object sender, EventArgs e)
    {
        HttpWebRequest req =
        WebRequest.Create("http://test.com/contact_ip.txt") as HttpWebRequest;

        HttpWebResponse resp = req.GetResponse() as HttpWebResponse;

        using (StreamReader sr = new StreamReader(resp.GetResponseStream()))
        {
            string ResponseText = sr.ReadToEnd();
            //ResponseText

            System.Diagnostics.Process.Start(".\\folder\\test.exe");
            // e.g.)) test.exe 127.0.0.1(ResponseText) 1234(port)
        }
    }

如何在test.exe

中包含IP地址和端口
e.g.)) .\folder\test.exe 127.0.0.1 4455

e.g.2)) Var ResponseText = ip Address

1 个答案:

答案 0 :(得分:2)

你可以试试这个:

private void button4_Click(object sender, EventArgs e)
{
    HttpWebRequest req =
    WebRequest.Create("http://test.com/contact_ip.txt") as HttpWebRequest;

    HttpWebResponse resp = req.GetResponse() as HttpWebResponse;

    using (StreamReader sr = new StreamReader(resp.GetResponseStream()))
    {
        string ResponseText = sr.ReadToEnd();
        //ResponseText

        System.Diagnostics.Process proc = new System.Diagnostics.Process();
        proc.StartInfo.FileName = @".\\folder\\test.exe";
        proc.StartInfo.Arguments = "127.0.0.1 4455";
        proc.Start();
    }
}