开发者

C# - Import lines from a text file into a Process.Start statement

开发者 https://www.devze.com 2023-03-13 18:35 出处:网络
I am curren开发者_开发知识库tly trying to import a list of executables from a text file into a statement:

I am curren开发者_开发知识库tly trying to import a list of executables from a text file into a statement:

private void button19_Click(object sender, EventArgs e)
{
    Process.Start("test.exe", <Process Name Here>);
}

So If a text file named process.txt contained:

notepad.exe

calc.exe

I would end up with:

Process.Start("test.exe", notepad.exe);

and

Process.Start("test.exe", cacl.exe);


This ought to be what you're after, Michael.

foreach(string exename in System.IO.File.ReadAllLines("yourfile.txt"))
{
  Process.Start("test.exe", "\"" + exename + "\"");
}


This will do it:

using (var reader = File.OpenText(pathToFile))
{
    string exe = "";

    while ((exe = reader.ReadLine()) != null)
    {
        Process.Start("test.exe", exe);
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消