microsoft / go-sqlcmd

The new sqlcmd, CLI for SQL Server and Azure SQL (winget install sqlcmd / sqlcmd create mssql / sqlcmd open ads)
https://learn.microsoft.com/sql/tools/sqlcmd/go-sqlcmd-utility
MIT License
343 stars 60 forks source link

Ctrl + C in Ubuntu breaks console #331

Closed JCoder01 closed 1 year ago

JCoder01 commented 1 year ago

input echo stops working when exiting with Ctrl + C. I Seems related to this https://github.com/peterh/liner/issues/104

There is no Close() when exiting: https://github.com/microsoft/go-sqlcmd/blob/main/pkg/console/console.go#L55

shueybubbles commented 1 year ago

@apoorvdeshmukh @stuartpa @JyotikaGargg - I'd like suggestions on a proper fix. I see 2 basic options.

  1. Keep the code "as is" and just add s.lineIO.Close() calls where sqlcmd.Run call os.Exit(0)
  2. Remove the os.Exit(0) and setupCloseHandler() calls from sqlcmd.Run and move them to cmd/sqlcmd

Option 1 keeps life simple for callers because they don't have to worry about assuring console close on ctrl-c before the process exits. Option 2 enables apps hosting pkg/sqlcmd to allow custom behaviors for ctrl-c. Some apps might want to host pkg/sqlcmd in interactive mode but not exit on ctrl-c, as they need to do some other cleanup first.