sqlcmdを使用してC#コードで自動的に実行しようとしている、非常に大きな複数のsqlファイルがあります。 ProcessStartInfoを使用してコマンドプロンプトを起動し、そこからsqlcmdを実行します。ただし、sqlcmdが最初のファイルの実行を終了すると、コマンドウィンドウは終了し、アプリケーションは「Wait for Exit」でハングアップします。 SQLファイルを実行した後、コマンドプロンプトが終了するようにするにはどうすればよいですか?コマンドプロンプトからc#で実行が終了した後にsqlcmdを閉じます
for (int i = 1; i <= fileCount; i++)
{
string readFile = fileToRead + "_" + i + ".sql";
string writeFile = fileToWrite + "_" + i + ".txt";
string commandString = "sqlcmd -S myservername -d mydatabasename -i " + readFile + " -o " + writeFile + " -a 32767";
ProcessStartInfo ProcessInfo;
ProcessInfo = new ProcessStartInfo("cmd.exe", "/K " + commandString);
ProcessInfo.CreateNoWindow = true;
ProcessInfo.UseShellExecute = false;
ProcessInfo.RedirectStandardOutput = true;
using (Process Process = Process.Start(ProcessInfo))
{
Process.WaitForExit(); //hangs here because window stays open, have to manually exit it to continue
}
}
次の行に/ Cで/ Kを交換して試してみてください/ Kの代わりに/ Cを使うと、コマンドプロンプトとタイプインを開くことができますCMD.EXE /? – Steve
実行しているプロセスで、ユーザーの入力を待っていますか? –