我正在尝试从shell脚本调用java jar。它适用于windown批处理脚本。我试图将这个工作批处理脚本翻译成一个shell脚本,但是没有让它工作。错误在哪里?
原始批处理文件(完美运行):
@echo off
rem set the right host here
set host=example.com
set port=8080
set urlPartBeforeApiVersion=/project/api
rem geographical region
set west=47.358352
set south=8.493598
set east=47.406704
set north=8.560889
set numberOfVehicles=10
set idPerfix=SIM_KSDN128D
set vehicleSpeed=40
set gpsSendInterval=10
set cloudmadeApiKey=kldhfjsghjf83hf83hf83hf89whs89
java -jar %~p0dist/application.jar %host% %port% %west% %south% %east% %north% %numberOfVehicles% %idPerfix% %vehicleSpeed% %gpsSendInterval% %urlPartBeforeApiVersion% %cloudmadeApiKey%
pause
shell脚本(不起作用):
#!/bin/sh
host="example.com"
port="8080"
urlPartBeforeApiVersion="/project/api"
west="47.358352"
south="8.493598"
east="47.406704"
north="8.560889"
numberOfVehicles="10"
idPerfix="SIM_KSDN128D"
vehicleSpeed="40"
gpsSendInterval="10"
cloudmadeApiKey="kldhfjsghjf83hf83hf83hf89whs89"
java -jar $(dirname $0)/dist/application.jar $host $port $west $south $east $north $numberOfVehicles $idPerfix $vehicleSpeed $gpsSendInterval $urlPartBeforeApiVersion $cloudmadeApiKey
应用程序抛出Java NumberFormatException并退出。我在Windows 7和centos上测试了cygwin上的脚本。
答案 0 :(得分:1)
当你的bash脚本有DOS行分隔符时,这是许多奇妙的事情之一。
通过dos2unix
,sed -i 's/\r//'
,tr -d '\r'
或您提供的任何内容运行您的脚本,然后重试。
为了将来参考,每当您看到一行以垃圾开头并被偷偷地截断时,例如
"xception [...]: For input string: "8080
而不是
Exception [...]: For input string: "8080"
你知道你正在处理回车问题。