C#-将文本文件中的行导入Process.Start语句
本文关键字:导入 Process Start 语句 文本 文件 C#- | 更新日期: 2023-09-27 17:59:16
我目前正试图将文本文件中的可执行文件列表导入到语句中:
private void button19_Click(object sender, EventArgs e)
{
Process.Start("test.exe", <Process Name Here>);
}
因此,如果一个名为process.txt的文本文件包含:
notepad.exe
calc.exe
我最终会得到:
Process.Start("test.exe", notepad.exe);
和
Process.Start("test.exe", cacl.exe);
这应该是你想要的,Michael。
foreach(string exename in System.IO.File.ReadAllLines("yourfile.txt"))
{
Process.Start("test.exe", "'"" + exename + "'"");
}
这样做:
using (var reader = File.OpenText(pathToFile))
{
string exe = "";
while ((exe = reader.ReadLine()) != null)
{
Process.Start("test.exe", exe);
}
}