///////////////////////////////////////////////////////////////////////////
class Program
{
static void pause()
{
Console.Write(“Press any key to continue . . . “);
Console.ReadKey(true);
}
static void Main(string[] args)
{
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = “curl.exe”; // Specify exe name.
start.Arguments = “-k https://www.moi.gov.tw/”;
start.UseShellExecute = false;
start.RedirectStandardOutput = true;
// Start the process.
using (Process p = Process.Start(start))
{
// Read in all the text from the process with the StreamReader
using (StreamReader reader = p.StandardOutput)
{
string result = reader.ReadToEnd();
Console.Write(result);
StreamWriter sw = new StreamWriter(“data.txt”);
sw.WriteLine(result);// 寫入文字
sw.Close();// 關閉串流
}
}
pause();
}
}
}