> I have a script that uses Perl's system() fuction to execute an osql
> command:
> system("osql -Usa -Ppwd -Smyserver -Q\"select name from
> master..sysdatabases\"");
> That command dosn't work - it just displays the osql help page as
> though I had made an error. However, the following command does work:
> system("osql -Usa -Ppwd -Smyserver -Q\"sp_who2\"");
> It returns the list of current SQL Server processes. What gives? Why
> would it execute a stored procedure but not a simple select command?
Do any of the following work?
system(qw(osql -Usa -Ppwd -Smyserver -Qsp_who2));
system(qw(osql -Usa -Ppwd -Smyserver),
"-Qselect name from master..sysdatabases");
system(qw(osql -Usa -Ppwd -Smyserver),
"-Qselect name from master.sysdatabases");
system(qq(osql -Usa -Ppwd -Smyserver -Q"sp_who2"));
system(qq(osql -Usa -Ppwd -Smyserver ).
qq(-Q"select name from master..sysdatabases"));
system(qq(osql -Usa -Ppwd -Smyserver ).
qq(-Q"select name from master.sysdatabases"));
Also, have you considered doing:
use DBI;
my $dbh = DBI->connect(
"DBI:ODBC:myserver",
"sa", "pwd",
{RaiseError => 1},
) or die $DBI::errstr;
my $sth = $dbh->prepare(
qq(select name from master.sysdatabases)
); # or maybe master..sysdatabases
$sth->execute;
while( my ($name) = $sth->fetchrow ) {
print $name, "\n";
Quote:}
__END__
[all untested]
--
pack 'u', pack 'H*', 'ab5cf4021bafd28972030972b00a218eb9720000';