【发布时间】:2011-02-20 12:55:58
【问题描述】:
嗨,根据我的最后一个问题here 我尝试编写一个 sql 编辑器或类似的东西,这样我尝试从 C# 连接到 CMD 并执行我的命令。 现在我的问题是在我无法获得 SQLPLUS 命令之后连接到 SQLPLUS,并且我查看的其他资源不满足我。请帮助我在连接到 sqlplus 后如何运行我的进程来运行我的 sql 命令?现在我使用这个代码:
//Create process
System.Diagnostics.Process pProcess = new System.Diagnostics.Process();
//strCommand is path and file name of command to run
pProcess.StartInfo.FileName = strCommand;
//strCommandParameters are parameters to pass to program
pProcess.StartInfo.Arguments = strCommandParameters;
pProcess.StartInfo.UseShellExecute = false;
//Set output of program to be written to process output stream
pProcess.StartInfo.RedirectStandardOutput = true;
//Optional
pProcess.StartInfo.WorkingDirectory = strWorkingDirectory;
//Start the process
pProcess.Start();
//Get program output
string strOutput = pProcess.StandardOutput.ReadToEnd();
//Wait for process to finish
pProcess.WaitForExit();
我定制了它。我分离了初始化,我创建了一次进程对象,但仍然有问题,运行第二个命令我使用这些代码进行第二次调用:
pProcess.StartInfo.FileName = strCommand;
//strCommandParameters are parameters to pass to program
pProcess.StartInfo.Arguments = strCommandParameters;
//Start the process
pProcess.Start();
//Get program output
string strOutput = pProcess.StandardOutput.ReadToEnd();
//Wait for process to finish
pProcess.WaitForExit();
提前致谢
【问题讨论】:
-
FWIW,那些 cmets 只是噪音......
-
你的意思是你想启动一次进程,但是向它发送多个命令?如果是这样,为什么不每次都发送多个命令从头开始整个过程(双关语不是故意的,但无论如何都很有趣)
-
正是...我只运行一次 sqlplus 之后我给用户/密码,如果它登录发送 Sql.PL 命令。我有点困惑:(实际上每次我尝试连接数据库并运行我的命令时都需要时间……但我不知道,也许其他软件也像这样使用?哈?有什么想法吗?