C#使用SQLite3和cmd.exe进行处理

时间:2014-03-19 17:10:04

标签: c# sqlite cmd

我正在尝试通过C#app运行cmd.exe以使用sqlite3命令。我无法弄清楚为什么它不能正常工作。也许有另一种选择?

我尝试解决方案是首先使用using System.Data.SQLite;结果这个库不包含sqlite3 shell函数。所以这不是一个选择。此外,我尝试独立调用sqlite3.exe,但这又不允许我从cmd请求某些命令。

Process SQLp = new Process();
SQLp.StartInfo.UseShellExecute = false;
SQLp.StartInfo.RedirectStandardOutput = true;
SQLp.StartInfo.RedirectStandardInput = true;
SQLp.StartInfo.WorkingDirectory = @"c:/temp"; //Contains sqlite3.exe
SQLp.StartInfo.FileName = "cmd.exe";
SQLp.Start();
StreamWriter SQLStreamWriter = SQLp.StandardInput;

inputText = "sqlite3 databasename";
SQLStreamWriter.WriteLine(inputText);
string output = SQLp.StandardOutput.ReadToEnd();
textBox1.Text = output;
SQLp.WaitForExit();

手动输入" sqlite3 databasename"在cmd中不会提供与上面相同的输出。实际上它似乎被忽略了。我的最终目标是能够发出上面的命令和.read abc.sql,.import xyz.csv等命令。

0 个答案:

没有答案