Forum Stats

  • 3,769,604 Users
  • 2,252,991 Discussions
  • 7,875,117 Comments

Discussions

sql /nolog doesn't work with GitBash on Windows

jgebal
jgebal Member Posts: 21 Blue Ribbon
edited Apr 27, 2019 9:41PM in SQLcl

When running "sql /nolog" from GitBash (on Windows x64) I get the following error:
Bad Option: C:/Program Files/Git/nolog                                                                               

Oracle SQL Developer Command-Line (SQLcl) help                                                                       

Usage 1: sql -H | -V
...

I'd like to use sql /nolog to format my changed project files as part of pre-commit hook in GIT.

Since git pre-commit hooks are Unix/Linux scripts, the sql is getting invoked from GitBash on windows.

GitBash is a Unix shell emulator in Windows.

There seems to be an issue with the "/nolog" option as it is getting misinterpreted (probably somewhere in Java?)

What can I do to make the "/nolog" option work for me in SQLCL from GitBash on Windows?

I've already changed the "sql" script to extend the CYGWIN check:

was:

  case `uname` in    CYGWIN*) cygwin=true;;  esac

is:

  case `uname` in    CYGWIN*) cygwin=true;;    MINGW64_NT-6.1*) cygwin=true;;  esac

sqlcl 19.1.

Windows 7 pro x64

Git for Windows version 2.20.1 (https://git-scm.com/downloads )

java version "1.8.0_201"

Java(TM) SE Runtime Environment (build 1.8.0_201-b09)

Tagged:

Best Answer

  • Gaz in Oz
    Gaz in Oz Member Posts: 3,784 Bronze Crown
    edited Apr 27, 2019 8:45PM Accepted Answer

    After failing to get sqlcl to even work in a native windows command shell I started to play about with sqlplus in git bash which exhibits the same behaviour:

    $ sqlplus /nolog...

    shows sqlplus help.

    Using strace to see where the issue might be it showed that it is in the creation of the child process, that is where /nolg is being appended to the Git directory:

    $ strace -n -q -t -u sqlplus /nologcreate_child: sqlplus C:/Git/nolog--- Process 12928 created--- Process 12928 loaded C:\Windows\System32\ntdll.dll at 00007ffdf7210000...

    etc and sqlplus help appears.

    Encapsulating /nolog in double-quotes, single quotes and escaping with backslash doesn't work, as you know.

    Double slashes "//" does.and /nolog gets passed to sqlplus without any git bash mis-interpretation:

    $ strace -n -q -t -u sqlplus //nologcreate_child: sqlplus /nolog--- Process 13616 created...

    So for sqlplus this works:

    $ sqlplus //nologSQL*Plus: Release 18.0.0.0.0 - Production on Sun Apr 28 10:33:02 2019Version 18.3.0.0.0Copyright (c) 1982, 2018, Oracle.  All rights reserved.SQL>

    You can suppress the banner with "-s" silent option:

    $ sqlplus -s //nologshow userUSER is ""

    So give sql //nolog or sql -s //nolog a go.

    jgebal

Answers

  • Gaz in Oz
    Gaz in Oz Member Posts: 3,784 Bronze Crown
    edited Apr 25, 2019 8:34PM

    Please copy/paste actual commands instead of tiny snippets of what you are doing.

    If it is a shell script then post that.

    It is very difficult to help debug your code when you don't show it.

  • jgebal
    jgebal Member Posts: 21 Blue Ribbon
    edited Apr 26, 2019 3:33PM

    Steps to reproduce:

    1. Download and install git for windows "Git-2.21.0-64-bit" with default options
      1. Git Bash + Git GUI
      2. Git from command line
      3. OpenSSH
      4. MinTTY (MSYS2)
    2. Download and unzip SQLCL 19.1 into c:\sqlcl
    3. Open git bash (from start menu)
    4. cd /c/sqlcl/bin
    5. invoke: ./sql
      At this point you will see:
      ... MINGW64 /c/sqlcl/bin
      $ ./sql
      Error: Could not find or load main class oracle.dbtools.raptor.scriptrunner.cmdline.SqlCli
    6. Edit the sql script and modify the function checkCygwin as mentioned above
    7. Add call to "checkCygwin" between lines
      setupClasspath
      # add checkCygwin here!!
      checkJavaLocation
    8. invoke: ./sql
      At this point the SQLCL works and I can connect to DB:
      MINGW64 /c/sqlcl/bin
      $ ./sql
      SQLcl: Release 19.1 Production on Fri Apr 26 20:25:21 2019
      Copyright (c) 1982, 2019, Oracle.  All rights reserved.
      Username? (''?)
    9. invoke: ./sql /nolog
      At this point the SQLCL fails to start, as the "/NOLOG" is not getting recognized / interpreted properly.
      MINGW64 /c/sqlcl/bin
      $ ./sql /nolog
      Bad Option: C:/Program Files/Git/nolog

      Oracle SQL Developer Command-Line (SQLcl) help

      Usage 1: sql -H | -V

          -H             Displays the SQLcl version and the
                         usage help.
          -V             Displays the SQLcl version.

      Usage 2: sql  [<option>] [{ <logon> | /nolog}] [<start>]

        <option> is:  [-R <level>] [-S] [-verbose] [-oci] [-L[OGON] ]


    10. Try the same from Windows cmd and see it work:
      C:\sqlcl\bin>sql /nolog
      SQLcl: Release 19.1 Production on Fri Apr 26 20:29:53 2019
      Copyright (c) 1982, 2019, Oracle.  All rights reserved.
      SQL> exit

    I'm not sure how to explain this any better.

    "/nolog" Works from Windows CMD, doesn't work from GitBash.

  • Gaz in Oz
    Gaz in Oz Member Posts: 3,784 Bronze Crown
    edited Apr 26, 2019 8:50PM

    Thank you for taking the time to post a detailed explanation.

    ...so, you will need to:

    $ ./sql "/nolog"

    i.e. surround /nolog in double-quotes.

  • jgebal
    jgebal Member Posts: 21 Blue Ribbon
    edited Apr 27, 2019 10:23AM

    I have already tried that approach - it doesn't work:

    MINGW64 /c/sqlcl/bin$ ./sql "/nolog"Bad Option: C:/Program Files/Git/nologOracle SQL Developer Command-Line (SQLcl) helpUsage 1: sql -H | -V    -H             Displays the SQLcl version and the                   usage help.

    Inside the "sql" script itself, the input parameters are already getting passed as "" into java in line:

    $JAVA  $CUSTOM_JDBC $CYGWIN "${APP_VM_OPTS[@]}" -client $DEBUG -cp "$CPLIST" oracle.dbtools.raptor.scriptrunner.cmdline.SqlCli "[email protected]"

    I have even echoed the command itself to see what it is passing:

    echo "$JAVA  $CUSTOM_JDBC $CYGWIN "${APP_VM_OPTS[@]}" -client $DEBUG -cp "$CPLIST" oracle.dbtools.raptor.scriptrunner.cmdline.SqlCli \"$@\""$JAVA  $CUSTOM_JDBC $CYGWIN "${APP_VM_OPTS[@]}" -client $DEBUG -cp "$CPLIST" oracle.dbtools.raptor.scriptrunner.cmdline.SqlCli "[email protected]"

    This is what I get:

     MINGW64 /c/sqlcl/bin$ ./sql "/nolog"C:\jdk1.8.0_201/bin/java   -Djline.terminal=jline.UnixTerminal -Djava.awt.headless=true -Dapple.awt.UIElement=true -Xss10M -client  -cp C:\sqlcl\lib\dbtools-sqlcl.jar;C:\sqlcl\lib\jansi.jar;C:\sqlcl\lib\drivers\*;C:\sqlcl\lib\ext\*;C:\rdbms\jlib\xdb6.jar;C:\jdbc\lib\ojdbc8.jar;C:\jlib\orai18n-utility.jar;C:\jlib\orai18n-mapping.jar;C:\jlib\orai18n.jar;C:\modules\oracle.xdk\xmlparserv2.jar; [...snap...] C:\sqlcl\lib\jline.jar;C:\sqlcl\lib\antlr-runtime.jar;C:\sqlcl\lib\jansi.jar;. oracle.dbtools.raptor.scriptrunner.cmdline.SqlCli "/nolog"Bad Option: C:/Program Files/Git/nologOracle SQL Developer Command-Line (SQLcl) helpUsage 1: sql -H | -V    -H             Displays the SQLcl version and the...

    Full text: of the echo output:

    C:\jdk1.8.0_201/bin/java   -Djline.terminal=jline.UnixTerminal -Djava.awt.headless=true -Dapple.awt.UIElement=true -Xss10M -client  -cp C:\sqlcl\lib\dbtools-sqlcl.jar;C:\sqlcl\lib\jansi.jar;C:\sqlcl\lib\drivers\*;C:\sqlcl\lib\ext\*;C:\rdbms\jlib\xdb6.jar;C:\jdbc\lib\ojdbc8.jar;C:\jlib\orai18n-utility.jar;C:\jlib\orai18n-mapping.jar;C:\jlib\orai18n.jar;C:\modules\oracle.xdk\xmlparserv2.jar;C:\sqlcl\lib\javax.json.jar;C:\sqlcl\lib\javax.json-api.jar;C:\sqlcl\lib\xmlparserv2.jar;C:\sqlcl\lib\commons-logging.jar;C:\sqlcl\lib\orai18n.jar;C:\sqlcl\lib\xmlparserv2-sans-jaxp-services.jar;C:\sqlcl\lib\orai18n-collation.jar;C:\sqlcl\lib\jackson-databind.jar;C:\sqlcl\lib\xdb6.jar;C:\sqlcl\lib\jackson-core.jar;C:\sqlcl\lib\stringtemplate.jar;C:\sqlcl\lib\oraclepki.jar;C:\sqlcl\lib\jackson-annotations.jar;C:\sqlcl\lib\osdt_core.jar;C:\sqlcl\lib\httpmime.jar;C:\sqlcl\lib\osdt_cert.jar;C:\sqlcl\lib\httpcore.jar;C:\sqlcl\lib\orajsoda.jar;C:\sqlcl\lib\httpclient.jar;C:\sqlcl\lib\orai18n-utility.jar;C:\sqlcl\lib\ojdbc8.jar;C:\sqlcl\lib\dbtools-sqlcl.jar;C:\sqlcl\lib\dbtools-net.jar;C:\sqlcl\lib\dbtools-http.jar;C:\sqlcl\lib\dbtools-common.jar;C:\sqlcl\lib\orai18n-servlet.jar;C:\sqlcl\lib\jsch.jar;C:\sqlcl\lib\commons-codec.jar;C:\sqlcl\lib\jdbcrest.jar;C:\sqlcl\lib\orai18n-mapping.jar;C:\sqlcl\lib\jline.jar;C:\sqlcl\lib\antlr-runtime.jar;C:\sqlcl\lib\jansi.jar;. oracle.dbtools.raptor.scriptrunner.cmdline.SqlCli "/nolog"

    The "/nolog" is passed into Java itself as argument regardless if I use the double-quotes or not.

    MINGW64 /c/sqlcl/bin$ ./sql /nologC:\jdk1.8.0_201/bin/java   -Djline.terminal=jline.UnixTerminal -Djava.awt.headless=true -Dapple.awt.UIElement=true -Xss10M -client  -cp C:\sqlcl\lib\dbtools-sqlcl.jar;[...snap...]C:\sqlcl\lib\jansi.jar;. oracle.dbtools.raptor.scriptrunner.cmdline.SqlCli "/nolog"Bad Option: C:/Program Files/Git/nologOracle SQL Developer Command-Line (SQLcl) help...

    Any ideas?

  • Andris Perkons-Oracle
    Andris Perkons-Oracle Posts: 1,099 Employee
    edited Apr 27, 2019 2:28PM
    Any ideas?

    Why do you need to run sql with GitBash if it already runs natively on Windows?

  • jgebal
    jgebal Member Posts: 21 Blue Ribbon
    edited Apr 27, 2019 4:30PM

    Because, as stated originally, I want to call sqlcl with nolog to format changed files as part of a pre-commit hook in git.

    Git hooks are shell (unix) scripts and on Windows they get invoked using GitBash as part of pre-commit actions.

    Hope this clarifies.

  • Gaz in Oz
    Gaz in Oz Member Posts: 3,784 Bronze Crown
    edited Apr 27, 2019 8:45PM Accepted Answer

    After failing to get sqlcl to even work in a native windows command shell I started to play about with sqlplus in git bash which exhibits the same behaviour:

    $ sqlplus /nolog...

    shows sqlplus help.

    Using strace to see where the issue might be it showed that it is in the creation of the child process, that is where /nolg is being appended to the Git directory:

    $ strace -n -q -t -u sqlplus /nologcreate_child: sqlplus C:/Git/nolog--- Process 12928 created--- Process 12928 loaded C:\Windows\System32\ntdll.dll at 00007ffdf7210000...

    etc and sqlplus help appears.

    Encapsulating /nolog in double-quotes, single quotes and escaping with backslash doesn't work, as you know.

    Double slashes "//" does.and /nolog gets passed to sqlplus without any git bash mis-interpretation:

    $ strace -n -q -t -u sqlplus //nologcreate_child: sqlplus /nolog--- Process 13616 created...

    So for sqlplus this works:

    $ sqlplus //nologSQL*Plus: Release 18.0.0.0.0 - Production on Sun Apr 28 10:33:02 2019Version 18.3.0.0.0Copyright (c) 1982, 2018, Oracle.  All rights reserved.SQL>

    You can suppress the banner with "-s" silent option:

    $ sqlplus -s //nologshow userUSER is ""

    So give sql //nolog or sql -s //nolog a go.

    jgebal
  • jgebal
    jgebal Member Posts: 21 Blue Ribbon
    edited Apr 27, 2019 9:40PM

    Awesome!

    Thanks a million.

    I've tried many different options like:

    \/nolog

    \\/nolog

    "\/nolog"

    "\\/nolog"

    '/nolog'

    etc.

    but didn't give a try to "//" instead of "/"

    ./sql //nolog does the trick!

    MINGW64 /c/sqlcl/bin$ ./sql //nologC:\jdk1.8.0_201/bin/java   -Djline.terminal=jline.UnixTerminal -Djava.awt.headless=true -Dapple.awt.UIElement=true -Xss10M -client  -cp C:\sqlcl\lib\dbtools-sqlcl.jar;C:\sqlcl\lib\jansi.jar;C:\sqlcl\lib\drivers\*;C:\sqlcl\lib\ext\*;C:\rdbms\jlib\xdb6.jar;C:\jdbc\lib\ojdbc8.jar;C:\jlib\orai18n-utility.jar;C:\jlib\orai18n-mapping.jar;C:\jlib\orai18n.jar;C:\modules\oracle.xdk\xmlparserv2.jar;C:\sqlcl\lib\javax.json.jar;C:\sqlcl\lib\javax.json-api.jar;C:\sqlcl\lib\xmlparserv2.jar;C:\sqlcl\lib\commons-logging.jar;C:\sqlcl\lib\orai18n.jar;C:\sqlcl\lib\xmlparserv2-sans-jaxp-services.jar;C:\sqlcl\lib\orai18n-collation.jar;C:\sqlcl\lib\jackson-databind.jar;C:\sqlcl\lib\xdb6.jar;C:\sqlcl\lib\jackson-core.jar;C:\sqlcl\lib\stringtemplate.jar;C:\sqlcl\lib\oraclepki.jar;C:\sqlcl\lib\jackson-annotations.jar;C:\sqlcl\lib\osdt_core.jar;C:\sqlcl\lib\httpmime.jar;C:\sqlcl\lib\osdt_cert.jar;C:\sqlcl\lib\httpcore.jar;C:\sqlcl\lib\orajsoda.jar;C:\sqlcl\lib\httpclient.jar;C:\sqlcl\lib\orai18n-utility.jar;C:\sqlcl\lib\ojdbc8.jar;C:\sqlcl\lib\dbtools-sqlcl.jar;C:\sqlcl\lib\dbtools-net.jar;C:\sqlcl\lib\dbtools-http.jar;C:\sqlcl\lib\dbtools-common.jar;C:\sqlcl\lib\orai18n-servlet.jar;C:\sqlcl\lib\jsch.jar;C:\sqlcl\lib\commons-codec.jar;C:\sqlcl\lib\jdbcrest.jar;C:\sqlcl\lib\orai18n-mapping.jar;C:\sqlcl\lib\jline.jar;C:\sqlcl\lib\antlr-runtime.jar;C:\sqlcl\lib\jansi.jar;. oracle.dbtools.raptor.scriptrunner.cmdline.SqlCli "//nolog"SQLcl: Release 19.1 Production on Sun Apr 28 02:37:25 2019Copyright (c) 1982, 2019, Oracle.  All rights reserved.SQL> 
  • jgebal
    jgebal Member Posts: 21 Blue Ribbon
    edited Apr 27, 2019 9:41PM

    It would be great to have SQLCL support GitBash natively however.

    Currently it requires editing the "sql" script to get it going (CYGWIN stuff).