简体   繁体   English

如何在Perl中打开外部命令(sqlplus)并连续使用它而无需重新启动

[英]How to open external command(sqlplus) and use it continuously without restart in Perl

I am beginner in Perl script. 我是Perl脚本的初学者。 and am writing perl script which opens external command ( sqlplus ). 并且正在编写打开外部命令(sqlplus)的perl脚本。 I want to open sqlplus with prelim setting, and get session information periodically. 我想使用预先设置打开sqlplus,并定期获取会话信息。 That is, After opening sqlplus with (oradebug setmypid) and (oradebug direct_access set mode=unsafe),then I want to send retrieval query(oradebug direct_access select * from x\\$ksuse\\n) continuously without restart sqlplus. 也就是说,用(oradebug setmypid)和(oradebug direct_access set mode = unsafe)打开sqlplus之后,我想连续发送检索查询(oradebug direct_access select * from x \\ $ ksuse \\ n),而无需重新启动sqlplus。

Following code might make you understand my question better 以下代码可能使您更好地理解我的问题

my $set = "oradebug setmypid;\n oradebug direct_access set mode=unsafe;\n oradebug direct_access select * from x\$ksuse\n";
open(PIPE, '|-', "/opt/oracle/product/11.2.0/db_1/bin/sqlplus -prelim system/oracle as sysdba");

print PIPE $set;    #if I call this call continuously, it means I open sqlplus again, again...This is not what I want^^

Is there any way of running retrieval query continuously after opening sqlplus once? 打开sqlplus一次后,有什么方法可以连续运行检索查询吗?

Thank you in advance 先感谢您

Generally speaking Expect is rather capable. 一般来说, Expect具有相当的能力。 There are lots of intricacies to handle when interfacing with an interactive shell command and Expect handles many of them for you. 与交互式shell命令交互时,要处理许多复杂的事情,Expect可以为您处理其中的许多问题。

However I must ask are you certain this (interfacing with sqlplus from perl) is the best approach? 但是我必须问您是否确定这是最好的方法(从perl与sqlplus进行接口连接)? I'm not nearly enough of an Oracle expert to understand what your code is wanting to achieve, but have you tried sqlplus start syntax 我对Oracle专家的了解还不足以了解您的代码想要实现的目标,但是您是否尝试过sqlplus start语法

in query.sql : query.sql

oradebug setmypid;
oradebug direct_access set mode=unsafe;
oradebug direct_access select * from x$ksuse;
exit;

in shell: 在外壳中:

/opt/oracle/product/11.2.0/db_1/bin/sqlplus -prelim system/oracle as sysdba @query >data.txt

This should put data.txt in the current working directory with your results. 这会将data.txt和结果一起放在当前的工作目录中。

Also, perl DBI is rather capable too, although I must say I don't understand what your code is trying to do so I don't know if DBI is able to help you with that. 另外,perl DBI也相当有能力,尽管我必须说我不明白您的代码正在尝试做什么,所以我不知道DBI是否能够为您提供帮助。 Google is your friend here. Google是您的朋友。

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM