在我的項目中,我有一個jar文件(由其他開發人員編寫)將內容從pdf複製到文本文件。使用python多線程概念,我試圖執行這個jar。如何在python多線程中執行jar文件
當我運行這個腳本後,我能夠看到文本文件被創建。但文件大小爲0KB。爲什麼內容不會複製到此文件中。但是我試着在命令行中運行這個jar,這個按預期工作。有人可以告訴請提供解決方案嗎?
from threading import Thread
import os
import sys
import time
import urllib2
from lxml import etree, html
import re
import Queue
import traceback
def createfile(x):
try:
file="test_"+str(x)
print "java -jar tika-app-1.1.jar -t --encoding=utf8 \"%s\" > \"%s\" "%("C:\\samplefile.pdf",file)
os.system("java -jar tika-app-1.1.jar -t --encoding=utf8 \"%s\" > \"%s\" "%("C:\tmp\samplefile.pdf",file))
except Exception,e:
print "excet",traceback.format_exc()
def process():
try:
result = Queue.Queue()
threads = [Thread(target=createfile, args=(x,)) for x in range(1,5)]
for t in threads:
t.start()
for t in threads:
t.join()
except:
print "exception",traceback.format_exc()
pass
end_time = time.time()
print "Estimate time", end_time - start_time
if __name__ == '__main__':
process()
我的輸出:
Exception in thread "main" java.net.MalformedURLException: unknown protocol: c
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at org.apache.tika.cli.TikaCLI.process(TikaCLI.java:393)
at org.apache.tika.cli.TikaCLI.main(TikaCLI.java:101)
Exception in thread "main" java.net.MalformedURLException: unknown protocol: c
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at org.apache.tika.cli.TikaCLI.process(TikaCLI.java:393)
at org.apache.tika.cli.TikaCLI.main(TikaCLI.java:101)
Exception in thread "main" java.net.MalformedURLException: unknown protocol: c
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at org.apache.tika.cli.TikaCLI.process(TikaCLI.java:393)
at org.apache.tika.cli.TikaCLI.main(TikaCLI.java:101)
Exception in thread "main" java.net.MalformedURLException: unknown protocol: c
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at org.apache.tika.cli.TikaCLI.process(TikaCLI.java:393)
at org.apache.tika.cli.TikaCLI.main(TikaCLI.java:101)
Estimate time 1.73799991608
'print'命令的輸出是什麼? – 2014-10-30 10:14:43
你確定你不必反斜槓那些反斜槓嗎?可能使用原始字符串... – NaeiKinDus 2014-10-30 10:18:27
輸出打印命令:java -jar tika-app-1.1.jar -t --encoding = utf8「C:\ tmp \ sample.pdf」>「test_1」java -jar tika- app-1.1.jar -t --encoding = utf8「C:\ tmp \ sample.pdf」>「test_2」java -jar tika-app-1.1.jar -t --encoding = utf8「C:\ tmp \ sample .pdf「 >」test_3「java -jar tika-app-1.1.jar -t --encoding = utf8」C:\ tmp \ sample.pdf「>」test_4「 – fewtalks 2014-10-30 10:19:50