Postgresクライアントを起動して維持しようとしているので、いくつかのSQLコマンドを送信して、各コマンドの結果を収集できます。私の現在の問題は、コマンドを送信するためのファイルハンドルを閉じない限り、最初のコマンドセットがプロセスに送信されないように見えることです。ただし、ファイルハンドルを閉じると、プログラムの目的全体が無効になります。
コードは次のとおりです。
my ($child_read, $child_write);
our $pid = open2($child_read, $child_write, '../psql -p 2070 super');
print STDOUT $pid . "\n";
$child_write->autoflush(1);
my $output1;
my $theCommands = "set schema 'super'; \n select count(*) from MyTable;";
print $child_write $theCommands;
close($child_write);
print "About to try and get query results. \n";
while (<$child_read>)
{
print "$_";
}
上記のコードは機能します。クエリの結果を取得しますが、SQLコマンドを実行する唯一の方法は、$child_writeファイルハンドルを閉じることです。閉じないと、行を読み込もうとしたときにプログラムがハングします。
$ child_writeファイルハンドルを閉じずにSQLコマンドをPostgresクライアントに送信するにはどうすればよいですか?