有一個bat 內容是start 123.exe 127.0.0.1 4545 , 是運行123.exe 去指定的ip 和端口
如何用c#是如何表達呢?
我知道以下代碼是可以運行123.exe , 但如何加入指定的ip和端口呢??
public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            Process game= new Process();
            // FileName 是要執行的檔案
            game.StartInfo.FileName = "123.exe";
            game.Start();
        }
    }
請使用 Environment.GetCommandLineArgs() 方法。它會傳回字串陣列,第一個元素是執行檔名稱,第二個以後才是你傳入的參數。
範例:
<pre class="c" name="code">
String[] arguments = Environment.GetCommandLineArgs();
Console.WriteLine("GetCommandLineArgs: {0}", String.Join(", ", arguments));
MSDN 上的說明:Environment.GetCommandLineArgs Method