我知道我的標題與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);
}
我想避免執行多個窗口,我想在同一個窗口中執行每個命令行。
我的代碼是好的還是替代?
感謝