in reply to SQLPLUS connect database

At the simplest, you could do:

my $result = qx{$ENV{ORACLE_HOME}/bin/sqlplus -L -V scott/scott \@data +base 2>&1};

You can read the documentation for qx/.../ in perlop. Probably a better solution would be to use Capture::Tiny:

use Capture::Tiny qw(capture); my ($stdout, $stderr, $exit) = capture { system("$ENV{ORACLE_HOME}/bin/sqlplus", '-L', '-V', 'scott/scott', + '@database'); };

Your original code escaped the @, so I carried that through in my examples. I'm not certain if that's intentional or not.


Dave

Replies are listed 'Best First'.
Re^2: SQLPLUS connect database
by ytjPerl (Scribe) on Jul 24, 2019 at 14:16 UTC
    Hi Dave, yes. I added '/' to escape @ as it was considering @ as global symbol. I tried to use capture with the connected db, stdout output is "SQL*Plus: Release 12.1.0.2.0 Production" stder output is blank and exit output is 0. the output is the same with the down db. My intention is to verify database connection, so it is not a solution for me. And I cannot use DBI module.
      The TNSPING utility can be used to test an Oracle Service Name. To use it:

      1.Open a Command Prompt (click Start, click Run, type cmd, and then click OK).

      2.Type tnsping <service name> (for Oracle 7.3 or Oracle 8i and later) or tnsping80 <service name> (for Oracle 8.0), and then press enter.

      The TNS Ping Utility will result in an "OK" or a "Connect failed" message. [...]
      This was basically the first result searching for "oracle test connection command line" btw. Sauce


      holli

      You can lead your users to water, but alas, you cannot drown them.
        I tried tnsping, it only shows me whatever I configured in tnsnames.ora