2011-03-24 96 views

回答

0

如果您正在使用此報表/網頁/等我想看看內置的模塊Intersystems爲Perl,Python,Ruby等提供了這些應用程序,可以爲您提供一個更清晰的數據庫接口。

這就是說,我做了一些外部調用,因爲我試圖從數據庫中獲取(通常是內部的)而不使用語言API。在這些情況下,我使用Perl。我使用Perl,因爲這樣做,我需要解析出菜單和其他我不想要的東西(你不會使用這些API)。以下是查看緩存中存在的所有用戶的簡單示例。

#!/usr/bin/perl 

use strict; 

my $username = 'user'; 
my $password = 'password'; 

my $val = `csession $instance -U %SYS << done 
$username 
$password 

d ^SECURITY 
1 
3 
* 
* 



h 
done`; 

my @users = split(/\n/, $val); 
my $in_users = 0; 
my $output = ''; 
foreach (@users){ 
    if($in_users){ 
    chomp($_); 
    if($_ eq ''){ 
     #no longer listing users 
     $in_users = 0; 
    } else { 
      $output .= "$_\n"; 
     } 
    } 
    $in_users = 1 if($_ =~ m/^\-\-\-\-/); # I started a the user list 
} 

print $output; # this prints out to the console 

#This prints to a file. 
open(OUTFILE, ">outfile.txt"); 
print OUTFILE $output; 

退房有關Perl和Python API以下鏈接 http://docs.intersystems.com/cache20102/csp/docbook/DocBook.UI.Page.cls?KEY=GBPLhttp://docs.intersystems.com/cache20102/csp/docbook/DocBook.UI.Page.cls?KEY=GBPY

0

這是一個有點hackish,但下面應該工作:

echo -e "username\npassword\nDO \$SYSTEM.SQL.Shell()\nfoo\nbar\nH\n" | cache > output 

每個命令你會在Caché中輸入後面跟着一個「\ n」表示換行。然後將其傳送到新會話中,並將其輸出寫入文件。