#!/usr/local/bin/perl -w

use FileHandle;
use IPC::Open2;

$MYSQL="/my/monty/sql/mysql --batch --unbuffered mysql";

open2(\*MYSQL_READ,\*MYSQL_WRITE,$MYSQL);
print STDOUT "select * from user;\n";
print MYSQL_WRITE "select * from user; select 'ok';\n";

$skr=<MYSQL_READ>;		# Get header
while (($_=<MYSQL_READ>) ne "ok\n")
{
  chop;
  print STDOUT  "user> $_ \n";
}
$skr=<MYSQL_READ>;		# Get ok row (found already ok header)


print STDOUT "select * from db; select 'ok';\n";
print MYSQL_WRITE "select * from db; select 'ok';\n";

close MYSQL_WRITE;

$skr=<MYSQL_READ>;		# Get header
while (($_=<MYSQL_READ>) ne "ok\n")
{
  chop;
  last if ($_ eq "ok");
  print STDOUT  "db> $_ \n";
}
$skr=<MYSQL_READ>;		# Get ok row (found already ok header)

print STDOUT "end\n";
exit 0;
