2016-07-08 41 views
1

Ich bin mit einem Dokument in einer PDF (unoconv) im Speicher und Drucke (pdftotext) im Terminal Umwandlung:Mit zwei Befehlen (Rohr mit |) mit Laich

unoconv -f pdf --stdout sample.doc | pdftotext -layout -enc UTF-8 - out.txt 

funktioniert. Jetzt möchte ich diesen Befehl mit child_process.spawn:

let filePath = "...", 
process = child_process.spawn("unoconv", [ 
    "-f", 
    "pdf", 
    "--stdout", 
    filePath, 
    "|", 
    "pdftotext", 
    "-layout", 
    "-enc", 
    "UTF-8", 
    "-", 
    "-" 
]); 

In diesem Fall wird nur der erste Befehl (vor der |) arbeitet. Kann ich tun, was ich versuche?

Danke.

UPDATE-

Ergebnis: sh -c- ....

bash-3.2$ sh -c- unoconv -f pdf --stdout /Users/fatimaalves/DEV/xx/_input/sample.doc | pdftotext -layout -enc UTF-8 - - 
sh: --: invalid option 
Usage: sh [GNU long option] [option] ... 
    sh [GNU long option] [option] script-file ... 
GNU long options: 
    --debug 
    --debugger 
    --dump-po-strings 
    --dump-strings 
    --help 
    --init-file 
    --login 
    --noediting 
    --noprofile 
    --norc 
    --posix 
    --protected 
    --rcfile 
    --restricted 
    --verbose 
    --version 
    --wordexp 
Shell options: 
    -irsD or -c command or -O shopt_option  (invocation only) 
    -abefhkmnptuvxBCHP or -o option 
Syntax Warning: May not be a PDF file (continuing anyway) 
Syntax Error: Couldn't find trailer dictionary 
Syntax Error: Couldn't find trailer dictionary 
Syntax Error: Couldn't read xref table 

Antwort

2

Alles mit dem Rohr beginnt, ist kein Argument zu unoconv. Es wird von der Shell verarbeitet, nicht von unoconv. Sie können es also nicht als Teil des Argumentarrays in unoconv übergeben.

Je nach Ihren Anforderungen gibt es verschiedene Möglichkeiten. Wenn Sie wissen, dass Sie nur auf UNIX-ähnlichen Betriebssystemen ausgeführt werden, können Sie Ihren Befehl als Argument an sh passieren:

process = child_process.spawn('sh', ['-c', 'unoconv -f pdf --stdout sample.doc | pdftotext -layout -enc UTF-8 - out.txt']); 
+0

Hmmm, ich bin mit einem Fenster, in diesem Fall, was soll ich verwenden? –

+0

alternativ könnten Sie die Ausgabe von dem ersten Befehl erhalten, und dann Spawn erneut für den 2. Befehl ausführen? –

+0

@Trott, ich habe versucht, in meinem Macbook, und das Ergebnis ist null –