Java &引用;为时已晚-";选择权;Perl和Shell脚本出错
我有一个jar应用程序,它有几个函数,其中一个是将HTML转换为XML。当我尝试运行以下简单命令时:Java &引用;为时已晚-";选择权;Perl和Shell脚本出错,java,html,xml,perl,nlp,Java,Html,Xml,Perl,Nlp,我有一个jar应用程序,它有几个函数,其中一个是将HTML转换为XML。当我尝试运行以下简单命令时: java -jar lt4el-cmd.jar send -l en "l2:https://en.wikipedia.org/wiki/Personal_computer" 我得到以下错误: ERROR [Thread-1]: html2base/html2base-wrapper.sh: Too late for "-C" option at html2base/html2xml.pl l
java -jar lt4el-cmd.jar send -l en "l2:https://en.wikipedia.org/wiki/Personal_computer"
我得到以下错误:
ERROR [Thread-1]: html2base/html2base-wrapper.sh: Too late for "-C" option at html2base/html2xml.pl line 1.
/tmp/lpc.30872.html: failed
cat: /tmp/lpc.30872.xml: No such file or directory
(LpcControl.java:229)
ERROR [Thread-1]: ana2ont/ana2ont.sh ${lang}: -:1: parser error : Document is empty
-:1: parser error : Start tag expected, '<' not found
Tokenization/tagging failed
^
-:1: parser error : Document is empty
unable to parse -
-:1: parser error : Document is empty
unable to parse -
(LpcControl.java:229)
ERROR [Thread-1]: Error in conversion: Error running conversion script (ana2ont/ana2ont.sh ${lang}): 6 (AppInterface.java:159)
以及html2base.sh
脚本:
#!/bin/bash
#
# Sample script for automated HTML -> XML conversion
#
# Miroslav Spousta <spousta@ufal.mff.cuni.cz>
# $Id: html2base.sh 462 2008-03-17 08:37:14Z qiq $
basedir=`dirname $0`;
# constants
HTML2XML_BIN=${basedir}/html2xml.pl
ICONV_BIN=iconv
TIDY_BIN=tidy
XMLLINT_BIN=xmllint
XSLTPROC_BIN=xsltproc
DTDPARSE_BIN=dtdparse
TMPDIR=/tmp
# default values
VERBOSE=0
ENCODING=
TIDY=0
VALIDATE=0
DTD=${basedir}/LT4ELBase.dtd
XSLT=${basedir}/LT4ELBase.xslt
usage()
{
echo "usage: html2base.sh [options] file(s)"
echo "XML -> HTML conversion script."
echo
echo " -e, --encoding=charset Convert input files from encoding to UTF-8 (none)"
echo " -d, --dtd=file DTD to be used for conversion and validation ($DTD)"
echo " -x, --xslt=file XSLT to be applied after conversion ($XSLT)"
echo " -t, --tidy Run HTMLTidy on input HTML files"
echo " -a, --validate Validate output XML files"
echo " -v, --verbose Be verbose"
echo " -h, --help Print this usage"
exit 1;
}
OPTIONS=`getopt -o e:d:x:tahv -l encoding:,dtd:,xlst,tidy,validate,verbose,help -n 'convert.sh' -- "$@"`
if [ $? != 0 ]; then
usage;
fi
eval set -- "$OPTIONS"
while true ; do
case "$1" in
-e | --encoding) ENCODING=$2; shift 2 ;;
-d | --dtd) DTD=$2; shift 2 ;;
-x | --xslt) XSLT=$2; shift 2 ;;
-t | --tidy) TIDY=1; shift 1;;
-a | --validate) VALIDATE=1; shift 1;;
-v | --verbose) VERBOSE=1; shift 1 ;;
-h | --help) usage; shift 1 ;;
--) shift ; break ;;
*) echo "Internal error!" ; echo $1; exit 1 ;;
esac
done
if [ $# -eq 0 ]; then
usage;
fi
DTD_XML=`echo "$DTD"|sed -e 's/\.dtd/.xml/'`
if [ "$VERBOSE" -eq 1 ]; then
VERBOSE=--verbose
else
VERBOSE=
fi
# create $DTD_XML if necessary
if [ ! -f "$DTD_XML" ]; then
if ! $DTDPARSE_BIN $DTD -o $DTD_XML 2>/dev/null; then
echo "cannot run dtdparse, cannot create $DTD_XML";
exit 1;
fi;
fi
# process file by file
total=0
nok=0
while [ -n "$1" ]; do
file=$1;
if [ -n "$VERBOSE" ]; then
echo "Processing $file..."
fi
f="$file";
result=0;
if [ -n "$ENCODING" ]; then
$ICONV_BIN -f "$ENCODING" -t utf-8 "$f" -o "$file.xtmp"
result=$?
error="encoding error"
f=$file.xtmp
fi
if [ "$result" -eq 0 ]; then
if [ "$TIDY" = '1' ]; then
$TIDY_BIN --force-output 1 -q -utf8 >"$file.xtmp2" "$f" 2>/dev/null
f=$file.xtmp2
fi
out=`echo $file|sed -e 's/\.x\?html\?$/.xml/'`
if [ "$out" = "$file" ]; then
out="$out.xml"
fi
$HTML2XML_BIN --simplify-ws $VERBOSE $DTD_XML -o "$out" "$f"
result=$?
error="failed"
fi
if [ "$result" -eq 0 ]; then
$XSLTPROC_BIN --path `dirname $DTD` $XSLT "$out" |$XMLLINT_BIN --noblanks --format -o "$out.tmp1" -
result=$?
error="failed"
mv "$out.tmp1" "$out"
if [ "$result" -eq 0 -a "$VALIDATE" = '1' ]; then
tmp=`dirname $file`/$DTD
delete=0
if [ ! -f $tmp ]; then
cp $DTD $tmp
delete=1
fi
$XMLLINT_BIN --path `dirname $DTD` --valid --noout "$out"
result=$?
error="validation error"
if [ "$delete" -eq 1 ]; then
rm -f $tmp
fi
fi
fi
if [ "$result" -eq 0 ]; then
if [ -n "$VERBOSE" ]; then
echo "OK"
fi
else
echo "$file: $error "
nok=`expr $nok + 1`
fi
total=`expr $total + 1`
rm -f $file.xtmp $file.xtmp2
shift;
done
if [ -n "$VERBOSE" ]; then
echo
echo "Total: $total, failed: $nok"
fi
#/bin/bash
#
#用于自动HTML->XML转换的示例脚本
#
#米罗斯拉夫·萨普斯塔
#$Id:html2base.sh 462 2008-03-17 08:37:14Z qiq$
basedir=`dirname$0`;
#常数
HTML2XML_BIN=${basedir}/HTML2XML.pl
ICONV_BIN=ICONV
整洁的
XMLLINT_BIN=XMLLINT
XSLTPROC_BIN=XSLTPROC
DTDPARSE_BIN=DTDPARSE
TMPDIR=/tmp
#默认值
详细=0
编码=
整洁=0
验证=0
DTD=${basedir}/LT4ELBase.DTD
XSLT=${basedir}/LT4ELBase.XSLT
用法()
{
echo“用法:html2base.sh[选项]文件”
echo“XML->HTML转换脚本”
回声
echo“-e,--encoding=charset将输入文件从编码转换为UTF-8(无)”
echo“-d,--dtd=用于转换和验证的文件dtd($dtd)”
echo“-x,--xslt=转换后要应用的文件xslt($xslt)”
echo“-t,--tidy在输入HTML文件上运行HTMLTidy”
echo“-a,--验证输出XML文件”
回声“-v,--verbose Be verbose”
echo“-h,--帮助打印此用法”
出口1;
}
OPTIONS=`getopt-oe:d:x:tahv-l encoding:,dtd:,xlst,tidy,validate,verbose,help-n'convert.sh'-“$@”`
如果[$?!=0];然后
用法;
fi
评估集--“$OPTIONS”
虽然真实;做
案件“$1”
-e |——编码)编码=$2;第二班;;
-d |--dtd)dtd=$2;第二班;;
-x |--xslt)xslt=$2;第二班;;
-t |--tidy)tidy=1;第1班;;
-a |--validate)validate=1;第1班;;
-v |--verbose)verbose=1;第1班;;
-h |——帮助)用法;第1班;;
--)转移;打破
*)回显“内部错误!”;回声1美元;出口1;;
以撒
完成
如果[$#-eq 0];然后
用法;
fi
DTD_XML=`echo“$DTD”| sed-e's/\.DTD/.XML/'`
如果[“$VERBOSE”-等式1];然后
详细=--详细
其他的
冗长的=
fi
#如有必要,创建$DTD_XML
如果[!-f“$DTD_XML”];然后
如果$DTDPARSE_BIN$DTD-o$DTD_XML 2>/dev/null;然后
echo“无法运行dtdparse,无法创建$DTD_XML”;
出口1;
fi;
fi
#逐文件处理
总数=0
nok=0
而[-n“$1”];做
文件=$1;
如果[-n“$VERBOSE”];然后
echo“正在处理$file…”
fi
f=“$file”;
结果=0;
如果[-n“$ENCODING”];然后
$ICONV_BIN-f“$ENCODING”-t utf-8“$f”-o“$file.xtmp”
结果=$?
error=“编码错误”
f=$file.xtmp
fi
如果[“$result”-等式0];然后
如果[“$TIDY”=“1”];然后
$TIDY_BIN--强制输出1-q-utf8>“$file.xtmp2”“$f”2>/dev/null
f=$file.xtmp2
fi
out=`echo$file | sed-e's/\.x\?html\?$/.xml/'`
如果[“$out”=“$file”];然后
out=“$out.xml”
fi
$HTML2XML_BIN——简化ws$VERBOSE$DTD_XML-o“$out”“$f”
结果=$?
error=“失败”
fi
如果[“$result”-等式0];然后
$XSLTPROC_BIN--path`dirname$DTD`$XSLT“$out”|$XMLLINT_BIN--noblanks--format-o“$out.tmp1”-
结果=$?
error=“失败”
mv“$out.tmp1”“$out”
如果[“$result”-等式0-a“$VALIDATE”=“1”];然后
tmp=`dirname$file`/$DTD
删除=0
如果[!-f$tmp];然后
cp$DTD$tmp
删除=1
fi
$XMLLINT_BIN--path`dirname$DTD`--valid--noout“$out”
结果=$?
error=“验证错误”
如果[“$delete”-等式1];然后
rm-f$tmp
fi
fi
fi
如果[“$result”-等式0];然后
如果[-n“$VERBOSE”];然后
回音“OK”
fi
其他的
echo“$file:$error”
挪威克朗=`expr$nok+1`
fi
总计=`expr$total+1`
rm-f$file.xtmp$file.xtmp2
转移;
完成
如果[-n“$VERBOSE”];然后
回声
echo“总计:$Total,失败:$nok”
fi
以及html2xml.pl文件的开头部分:
#!/usr/bin/perl -W -C
# Simple HTML to XML (subset of XHTML) conversion tool. Should always produce a
# valid XML file according to the output DTD file specified.
#
# Miroslav Spousta <spousta@ufal.mff.cuni.cz>
# $Id: html2xml.pl 461 2008-03-09 09:49:42Z qiq $
use HTML::TreeBuilder;
use HTML::Element;
use HTML::Entities;
use XML::LibXML;
use Getopt::Long;
use Data::Dumper;
use strict;
#/usr/bin/perl-W-C
#简单的HTML到XML(XHTML的子集)转换工具。应始终生成一个
#根据指定的输出DTD文件的有效XML文件。
#
#米罗斯拉夫·萨普斯塔
#$Id:html2xml.pl 461 2008-03-09 09:49:42Z qiq$
使用HTML::TreeBuilder;
使用HTML::元素;
使用HTML::实体;
使用XML::LibXML;
使用Getopt::Long;
使用数据::转储程序;
严格使用;
我似乎不知道问题出在哪里。那么
ERROR[Thread-1]
到底意味着什么呢?
谢谢错误源于在Perl脚本的shebang(
#!
)行上有-C
,但没有将-C
传递给Perl
。当有人这样做时,就会发生这种类型的错误
perl html2base/html2xml.pl ...
而不是
html2base/html2xml.pl ...
正如其他用户正确提到的那样,错误来自
html2xml.pl
脚本。我运行的是Ubuntu16.04.2系统,它带有默认的Perl5.22版本。正如上面提到的,在#上使用-C
选项(从perl5.10.1
)代码>行要求您在执行时也在命令行上指定它,我不知道该怎么做,因为我正在运行一个jar文件。相反,我安装了它,我使用它来获取早期版本的perl,并将我的perl脚本修改为:
#!/usr/bin/path/to/perlbrew/perl -W -C
# Simple HTML to XML (subset of XHTML) conversion tool. Should always produce a
# valid XML file according to the output DTD file specified.
#
# Miroslav Spousta <spousta@ufal.mff.cuni.cz>
# $Id: html2xml.pl 461 2008-03-09 09:49:42Z qiq $
#/usr/bin/path/to/perlbrew/perl-W-C
#简单的HTML到XML(XHTML的子集)转换工具。应始终生成一个
#根据指定的输出DTD文件的有效XML文件。
#
#米罗斯拉夫·萨普斯塔
#$Id:html2xml.pl 461 2008-03-09 09:49:42Z qiq$
在使用perlbrew时,在设置shell脚本时可能也很方便
感谢您的贡献。ERROR[Thread-1]
可能意味着Thread 1中的错误第一个错误在html2base/html2xml.pl中?您是这么说还是在问@克里斯图内里我在问-是c
#!/usr/bin/path/to/perlbrew/perl -W -C
# Simple HTML to XML (subset of XHTML) conversion tool. Should always produce a
# valid XML file according to the output DTD file specified.
#
# Miroslav Spousta <spousta@ufal.mff.cuni.cz>
# $Id: html2xml.pl 461 2008-03-09 09:49:42Z qiq $