Hi. I have a script in which I process data from standard input like this:
VOCAB_WITH_NEW_VOCAB_NOTE="$(echo "$VOCAB" | "${BASEX}" -i - -q $" copy $c := . modify ...
etc. etc.
The script has been working fine.
However, due to a defect in an earlier line in the script, during one test run, the value of $VOCAB was (incorrectly) an empty string.
But in this case, I got a quite unexpected result from the above invocation of BaseX.
I can easily repeat the same phenomenon out of the script's context thus:
$ echo '' | basex -i - -q '.' <vocabulary xmlns="http://vocabs.ands.org.au/registry/schema/2017/01/vocabulary" ... etc. etc.
In this case, rather than processing the empty string provided as standard input, BaseX fetched data from one of my databases.
Can I/how do I force the option "-i -" to mean "read data from standard input, and _only_ from standard input, even if that is empty"?
-- Richard Walker Australian Research Data Commons (ARDC) (formerly, Australian National Data Service, ANDS) 101 Liversidge Street The Australian National University Acton ACT 2601, Australia E: Richard.Walker@ardc.edu.au T: +61 2 6125 0584 W: ardc.edu.au W: www.ands.org.au
Hi Richard,
Thanks for reporting this.
I didn’t manage to reproduce this behavior. Do you work with the latest version of BaseX? If yes, could you possibly download a fresh version (e.g. the zip distribution) and tell us step by step how I can simulate the behavior?
Thanks in advance, all the best, Christian
On Tue, Aug 21, 2018 at 3:12 AM Richard Walker richard.walker@ardc.edu.au wrote:
Hi. I have a script in which I process data from standard input like this:
VOCAB_WITH_NEW_VOCAB_NOTE="$(echo "$VOCAB" | "${BASEX}" -i - -q $" copy $c := . modify ...
etc. etc.
The script has been working fine.
However, due to a defect in an earlier line in the script, during one test run, the value of $VOCAB was (incorrectly) an empty string.
But in this case, I got a quite unexpected result from the above invocation of BaseX.
I can easily repeat the same phenomenon out of the script's context thus:
$ echo '' | basex -i - -q '.' <vocabulary xmlns="http://vocabs.ands.org.au/registry/schema/2017/01/vocabulary" ... etc. etc.
In this case, rather than processing the empty string provided as standard input, BaseX fetched data from one of my databases.
Can I/how do I force the option "-i -" to mean "read data from standard input, and _only_ from standard input, even if that is empty"?
-- Richard Walker Australian Research Data Commons (ARDC) (formerly, Australian National Data Service, ANDS) 101 Liversidge Street The Australian National University Acton ACT 2601, Australia E: Richard.Walker@ardc.edu.au T: +61 2 6125 0584 W: ardc.edu.au W: www.ands.org.au
On 22 Aug 2018, at 3:44 am, Christian Grün christian.gruen@gmail.com wrote:
I didn’t manage to reproduce this behavior. Do you work with the latest version of BaseX?
9.0.2.
If yes, could you possibly download a fresh version (e.g. the zip distribution) and tell us step by step how I can simulate the behavior?
Further clarification/correction to what I reported:
* When I said "empty string", in fact the "problem" arises when standard input is _not_ empty, but includes just a blank line. * When standard input is empty, I get an exception NoSuchElementException. That is probably acceptable: at least, it is better than getting output that has nothing to do with the input data. * When I said "one of my databases", I think that _may_ have been wrong. It may be content from an XML file in the current directory (or, as you'll see below, from some part of the distribution) ... I can't easily tell.
What follows was done on a Mac; "$" is a placeholder for the shell prompt.
Three tests: * The first test shows what I expected to be the behaviour for data read from standard input. * The second test shows when standard input is empty (echo -n ''): an exception. * The third test shows when standard input contains just a blank line (echo ''): it seems to read from the factbook.xml data (from basex/etc/factbook.xml?)
$ mkdir basex-report $ cd basex-report $ wget http://files.basex.org/releases/9.0.2/BaseX902.zip ... output omitted ... $ unzip BaseX902.zip Archive: BaseX902.zip extracting: basex/.basexhome inflating: basex/BaseX.jar creating: basex/bin/ inflating: basex/bin/basex inflating: basex/bin/basex.bat ... etc. $ echo '<x />' | basex/bin/basex -i- -q '.' /Users/rwalker/basex-report/basex/.basex: writing new configuration file. <x/>$ <-- shell prompt printed immediately after output $ echo -n '' | basex/bin/basex -i- -q '.' Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:862) at java.util.Scanner.next(Scanner.java:1371) at org.basex.util.MainParser.string(MainParser.java:110) at org.basex.BaseX.parseArgs(BaseX.java:235) at org.basex.core.CLI.<init>(CLI.java:50) at org.basex.BaseX.<init>(BaseX.java:55) at org.basex.BaseX.main(BaseX.java:42) $ echo '' | basex/bin/basex -i- -q '.' <mondial> <continent id="f0_119" name="Europe"/> <continent id="f0_123" name="Asia"/> <continent id="f0_126" name="America"/> <continent id="f0_129" name="Australia/Oceania"/> <continent id="f0_132" name="Africa"/> <country id="f0_136" name="Albania" capital="f0_1461" population="3249136" datacode="AL" total_area="28750" population_growth="1.34" infant_mortality="49.2" gdp_agri="55" gdp_total="4100" inflation="16" indep_date="28 11 1912" government="emerging democracy" car_code="AL"> <name>Albania</name> <city id="f0_1461" country="f0_136" longitude="10.7" latitude="46.2"> <name>Tirane</name> ... etc.
Hi Richard,
Newlines (i.e., whitespace-only, non-empty strings) were treated identically to the "." file reference. As you can also supply absolute and relative file and directory paths as arguments for the -i flag, the factbook.xml file, which is located in a descendant directory of your current directory, was opened instead and bound to the context item.
This special case will now be checked. In addition, the error message for empty strings will now be suppressed. Feel free to check out the latest stable snapshot [1].
Best, Christian
[1] http://files.basex.org/releases/latest/
Further clarification/correction to what I reported:
- When I said "empty string", in fact the "problem" arises when standard input is _not_ empty, but includes just a blank line.
- When standard input is empty, I get an exception NoSuchElementException. That is probably acceptable: at least, it is better than getting output that has nothing to do with the input data.
- When I said "one of my databases", I think that _may_ have been wrong. It may be content from an XML file in the current directory (or, as you'll see below, from some part of the distribution) ... I can't easily tell.
What follows was done on a Mac; "$" is a placeholder for the shell prompt.
Three tests:
- The first test shows what I expected to be the behaviour for data read from standard input.
- The second test shows when standard input is empty (echo -n ''): an exception.
- The third test shows when standard input contains just a blank line (echo ''): it seems to read from the factbook.xml data (from basex/etc/factbook.xml?)
$ mkdir basex-report $ cd basex-report $ wget http://files.basex.org/releases/9.0.2/BaseX902.zip ... output omitted ... $ unzip BaseX902.zip Archive: BaseX902.zip extracting: basex/.basexhome inflating: basex/BaseX.jar creating: basex/bin/ inflating: basex/bin/basex inflating: basex/bin/basex.bat ... etc. $ echo '<x />' | basex/bin/basex -i- -q '.' /Users/rwalker/basex-report/basex/.basex: writing new configuration file. <x/>$ <-- shell prompt printed immediately after output $ echo -n '' | basex/bin/basex -i- -q '.' Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:862) at java.util.Scanner.next(Scanner.java:1371) at org.basex.util.MainParser.string(MainParser.java:110) at org.basex.BaseX.parseArgs(BaseX.java:235) at org.basex.core.CLI.<init>(CLI.java:50) at org.basex.BaseX.<init>(BaseX.java:55) at org.basex.BaseX.main(BaseX.java:42) $ echo '' | basex/bin/basex -i- -q '.'
<mondial> <continent id="f0_119" name="Europe"/> <continent id="f0_123" name="Asia"/> <continent id="f0_126" name="America"/> <continent id="f0_129" name="Australia/Oceania"/> <continent id="f0_132" name="Africa"/> <country id="f0_136" name="Albania" capital="f0_1461" population="3249136" datacode="AL" total_area="28750" population_growth="1.34" infant_mortality="49.2" gdp_agri="55" gdp_total="4100" inflation="16" indep_date="28 11 1912" government="emerging democracy" car_code="AL"> <name>Albania</name> <city id="f0_1461" country="f0_136" longitude="10.7" latitude="46.2"> <name>Tirane</name> ... etc.
On 23 Aug 2018, at 1:06 am, Christian Grün christian.gruen@gmail.com wrote:
Feel free to check out the latest stable snapshot [1].
Works well for me; thank you.
basex-talk@mailman.uni-konstanz.de