从代码中执行Sqlite3命令行工具



我正试图在c#代码中作为进程运行sqlite.exe工具,以便从文件中读取sql。

如果我在powershell中运行sqLite3工具,那么它工作正常(sqLite3.exe"mydatabase.db".read mySql.sql"(

但是,当我从c#代码中作为一个进程运行sqlite3工具时,mydatabase.db不会发生任何变化。当sqlite3终止时,它仍然是0b。我没有收到错误消息,sqlite3.exe的输出是一个空字符串,退出代码是1(在退出事件中验证(。有人知道为什么database.db为什么.sql文件中的记录没有添加到.db文件中吗?。

using (Process pProcess = new Process())
{
pProcess.StartInfo.FileName = sqlLite3ExePath;
pProcess.StartInfo.Arguments = $""{sqLitePath2}" ".read {sqlPath}"";;
pProcess.StartInfo.UseShellExecute = false;
pProcess.StartInfo.RedirectStandardOutput = true;
pProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;//System.Diagnostics.ProcessWindowStyle.Hidden;
pProcess.StartInfo.CreateNoWindow = false;//true; //not diplay a windows
pProcess.EnableRaisingEvents = true;
pProcess.Exited += PProcess_Exited;
pProcess.Start();
string output = pProcess.StandardOutput.ReadToEnd(); //The output result
pProcess.WaitForExit();
Debug.WriteLine(output);
}
正如CaiusJard在评论中所说,错误流中传递了一个错误。添加以下行告诉我我的路径是错误的。
pProcess.StartInfo.RedirectStandardError = true;
string error = pProcess.StandardError.ReadToEnd(); //The output result

路径分配器"\"已删除,因为路径已解析两次。设置参数一次,工具读取参数一次。替换"\"用"/"在我的道路上做了特技

最新更新