2017-08-14 2 views
-1

J'ai une application jar qui a plusieurs fonctions, dont l'une est de convertir HTML en XML. Lorsque je tente d'exécuter une commande simple comme:"Trop tard pour" -C "option" erreur Avec les scripts Perl et Shell

java -jar lt4el-cmd.jar send -l en "l2:https://en.wikipedia.org/wiki/Personal_computer" 

Je reçois les erreurs suivantes:

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) 

C'est le script html2base-wrapper.sh qui semble être là où la première erreur se produit.

#!/bin/bash 

if [ "$1" == "check" ]; then 
    . common.sh 
    check_binary perl || exit 1 
    check_perl_module HTML::TreeBuilder || exit 1 
    check_perl_module XML::LibXML || exit 1 
    check_binary tidy || exit 1 
    check_binary xmllint || exit 1 
    check_binary xsltproc || exit 1 
    exit 
fi 

cat >"$TMPDIR/lpc.$$.html" 
html2base/html2base.sh -d html2base/LT4ELBase.dtd -x html2base/LT4ELBase.xslt -t "$TMPDIR/lpc.$$.html" >&2 
cat "$TMPDIR/lpc.$$.xml"; 
rm -f "$TMPDIR"/lpc.$$.{ht,x}ml 

Et le script html2base.sh:

#!/bin/bash 
# 
# Sample script for automated HTML -> XML conversion 
# 
# Miroslav Spousta <[email protected]> 
# $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' -- "[email protected]"` 
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 

Et le début partie du fichier 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 <[email protected]> 
# $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; 

Je ne peux pas sembler figurer où le problème est. Et que signifie exactement ERROR [Thread-1]? Merci

+0

'ERREUR [Thread-1]' Probable signifie erreur dans le thread 1 – litelite

+2

La première erreur est dans html2base/html2xml.pl sûrement? –

+0

Est-ce que vous dites cela ou vous demandez? @ChrisTurner – TheSolider

Répondre

0

L'erreur était du script html2xml.pl que d'autres utilisateurs mentionné à juste titre. Je cours le système d'Ubuntu 16.04.2 qui vient avec une version 5.22 de perl par défaut. Et comme ce post mentionne, en utilisant l'option -C (à partir de perl 5.10.1) sur la ligne #! vous devez également l'indiquer sur la ligne de commande au moment de l'exécution, ce que je ne savais pas comment faire parce que je courais un fichier jar. J'ai installé perlbrew, au contraire, que je l'habitude d'obtenir une version antérieure de Perl et modifié mon script perl pour:

#!/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 <[email protected]> 
# $Id: html2xml.pl 461 2008-03-09 09:49:42Z qiq $ 

This pourrait également être utile dans la mise en place des scripts shell lors de l'utilisation perlbrew.

Merci pour les efforts en contribution.

1

L'erreur vient d'avoir -C sur le tralala (#!) ligne d'un script Perl, mais pas passer le -C-perl. Ce type d'erreur se produit lorsque quelqu'un fait

perl html2base/html2xml.pl ... 

au lieu de

html2base/html2xml.pl ... 
+0

Je viens de trouver que l'option: '-C' dans le script Perl donne des erreurs dans les versions récentes de Perl. Y at-il un moyen de contourner cela en donnant le fait que je l'exécute à partir d'un fichier jar compilé? Merci – TheSolider

+1

Oui, vous pouvez utiliser le correctif que j'ai fourni dans ma réponse. (Notez que le seul changement dans Perl est qu'il a commencé à détecter un bug qui existait déjà dans l'appelant.) – ikegami

+0

Cette commande: 'java -jar lt4el-cmd.jar envoie -l en. . .' appelle le script Perl et toutes les autres bibliothèques dont il a besoin. Comment puis-je résoudre ce problème puisque je ne lance pas 'perl html2base/html2xml.pl' sur la ligne de commande?Merci – TheSolider