【发布时间】:2013-09-22 00:49:55
【问题描述】:
我的 sqlplus 命令没有完成,它在密码行等待,它没有给我错误。
当我打开新的 cmd 窗口并粘贴此代码时,此代码没有问题!一切都好, 但我无法使用 process() 在 c# 上运行;
我的sqlplus命令文本:
Set ORACLE_SID=prod
Set ORACLE_HOME=C:\oracle\product\10.2.0\db_1
sqlplus -s
sys as sysdba
password
shutdown immediate
startup mount
recover standby database until cancel;
cancel
alter database open read only;
exit;
exit;
我试试这个:
C:\cmd.cmd
*********************************************
Set ORACLE_SID=prod
Set ORACLE_HOME=C:\oracle\product\10.2.0\db_1
sqlplus -s
sys as sysdba
manager
select * from dual;
exit;
*********************************************
Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = @"C:\cmd.cmd";
startInfo.RedirectStandardInput = true;
startInfo.RedirectStandardOutput = true;
startInfo.CreateNoWindow = true;
startInfo.UseShellExecute = false;
process = Process.Start(startInfo);
//output
string BatProcessResult = process.StandardOutput.ReadToEnd();
输出:
D:\AppPath\bin\Debug>设置 ORACLE_SID=prod
D:\AppPath\bin\Debug>设置 ORACLE_HOME=C:\oracle\product\10.2.0\db_1
D:\AppPath\bin\Debug>sqlplus -s
D:\AppPath\bin\Debug>sys as sysdba;
【问题讨论】:
-
我记不太清了,但在脚本中是这样的:
sqlplus -s "sys@wherever/password as sysdba"。由于空格,所以需要双引号。 -
谢谢我找到了解决方案,语法 username/pw@db
-
非常好——很高兴你找到了它!双引号可能是 unix/linux 的东西。请注意,Oracle 将接受
username/pw@db或username@db/pw。
标签: oracle command-line process command-line-arguments sqlplus