【发布时间】:2022-11-22 03:28:50
【问题描述】:
如何为以下代码生成 log.txt 文件?我还想查看在 C# 应用程序中生成的实时日志。
下面的 new.bat 文件运行以下命令:
py file1.py -p COM# write_test 0x10000 设备.bin
private void button1_Click_1(object sender, EventArgs e)
{
lbl_startingTest.Text = "Starting Test..";
lbl_Result.Text = "Running";
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.FileName = "C:\\test\\test\\bin\\Debug\\new.bat";
p.StartInfo.CreateNoWindow = true;
p.Start();
p.WaitForExit();
}
我尝试了以下代码来创建日志,但它不起作用。
string path = @"C:\\test\\logs" + System.DateTime.Now.ToShortTimeString() + ".txt";
if (!File.Exists(path))
{
// Create a file to write to.
using (StreamWriter sw = File.CreateText(path))
{
sw.WriteLine("PB");
sw.WriteLine("device");
sw.WriteLine("Test");
}
}
【问题讨论】:
-
首先,在
@和\`. If you put the@, you don't need to make the double`之间做出选择
标签: python c# batch-file logging binary