我知道我的标题与StackOverflow中的其他人一样,但我的意图是其他。在C#中使用相同的ProcessStartInfo实例执行多个命令(使用BCP)
我创建了一个C#函数,它使用BCP命令为我的数据库中的每个表创建BCP文件。下面的代码是一个示例,是函数的一部分。
List<string> tables = GetTables(); // a function which takes all tables from my database
string command = @"bcp ADatabase.dbo.{0} out {0}.bcp -n -Usa -Ppassword";
ProcessStartInfo processInfo = null;
try {
foreach (string table in tables) {
command = string.Format(command, table);
processInfo = new ProcessStartInfo("cmd", "/c " + command);
processInfo.RedirectStandardOutput = true;
processInfo.CreateNoWindow = false;
Process process = new Process();
process.StartInfo = processInfo;
process.Start();
string result = process.StandardOutput.ReadToEnd();
Console.WriteLine(result);
}
} catch (Exception e) {
Console.WriteLine(e.Message);
}
我想避免执行多个窗口,我想在同一个窗口中执行每个命令行。
我的代码是好的还是替代?
感谢