request: please don't use java.io.Console when -P is given
Friday, 24 September 2010 · 3 messages
GB
Godmar Back24 Sep 2010 07:31 #
The current version of BaseXClient uses java.io.Console, which makes redirecting input from stdin impossible. That makes it difficult to create any type of script that interacts with the database (essentially, it would require using 'expect' or equivalent).
As far as I can see, the only thing you need java.io.Console for is reading the password. Please do not use console if the user provides the password on the command line with -P.
Alternatively, or in addition, consider supporting a "source" command that reads commands from a file and sends them to the server.
- Godmar
AW
Andreas Weiler24 Sep 2010 09:43 #
Quoted text · Godmar Back · 2 lines
> Please do not use console if the user provides the password on the > command line with -P.
As i can see this is the case.
The password is just read with the System.Console() when it is not specified after the -P argument.
Quoted text · Godmar Back · 22 lines
Godmar Back schrieb: > The current version of BaseXClient uses java.io.Console, which makes > redirecting input from stdin impossible. That makes it difficult to > create any type of script that interacts with the database > (essentially, it would require using 'expect' or equivalent). > > As far as I can see, the only thing you need java.io.Console for is > reading the password. Please do not use console if the user provides > the password on the command line with -P. > > Alternatively, or in addition, consider supporting a "source" command > that reads commands from a file and sends them to the server. > > - Godmar > > ------------------------------------------------------------------------ > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >
GB
Godmar Back24 Sep 2010 16:36 #
Quoted text · Andreas Weiler · 10 lines
On Fri, Sep 24, 2010 at 3:43 AM, Andreas Weiler < andreas.weiler at uni-konstanz.de> wrote: > Please do not use console if the user provides the password on the command >> line with -P. >> > As i can see this is the case. > The password is just read with the System.Console() when it is not > specified after the -P argument. > >
That's not the problem. The problem is that you use System.console() when you should be using System.in in cases when the user specifies -P.
Try redirecting input from stdin to the BaseXClient - you'll see that it does not work. (It's a well-known limitation of java.io.Console). It leads to an infinite loop where BaseXClient ignores EOF. Really annoying.
Here for illustration what the problem is:
Quoted text · Andreas Weiler · 1 line
> java -cp ../WEB-INF/lib/basex-6.2.3.jar org.basex.BaseXClient -p 1985 -U
admin -P admin
BaseX 6.2.3 [Client]
Try "help" to get some information.
Quoted text · Andreas Weiler · 1 line
> create db test
Database 'test' created in 39.72 ms.
Quoted text · Andreas Weiler · 1 line
> xquery insert node <root /> into doc("test")
Query executed in 29.36 ms.
Quoted text · Andreas Weiler · 1 line
> xquery doc("test")/root
<root/>
Query executed in 1.94 ms.
Quoted text · Andreas Weiler · 1 line
> exit
Enjoy life.
Now when I put the commands in a file:
Quoted text · Andreas Weiler · 1 line
> cat testscript
create db test
xquery insert node <root /> into doc("test")
xquery doc("test")/root
exit
and then redirect stdin, it breaks:
Quoted text · Andreas Weiler · 1 line
> java -cp ../WEB-INF/lib/basex-6.2.3.jar org.basex.BaseXClient -p 1985 -U
admin -P admin < testscript
BaseX 6.2.3 [Client]
Try "help" to get some information.
Quoted text · Andreas Weiler · 8 lines
> Database 'test' created in 8.71 ms. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >
(and so on, I have to kill the program)
The reason is, as I said, that you're using java.io.Console when you should be using System.in
- Godmar
Written for BaseX 6. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery