首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从shell脚本调用java应用程序

从shell脚本调用java应用程序
EN

Stack Overflow用户
提问于 2013-07-29 16:28:51
回答 1查看 434关注 0票数 0

我正在尝试从shell脚本中调用一个java jar。它适用于一个下拉式批处理脚本。我试图将这个工作批处理脚本转换成一个shell脚本,但没有让它工作。窃听器在哪里?

原始批处理文件(工作正常):

代码语言:javascript
复制
@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脚本(不工作):

代码语言:javascript
复制
#!/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上测试了脚本。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-07-29 23:15:44

这是当bash脚本有DOS行分隔符时可以发生的许多奇妙的事情之一。

通过dos2unixsed -i 's/\r//'tr -d '\r'或任何可用的内容运行脚本,然后再试一次。

对于将来的参考,每当您看到一行以垃圾开头并被秘密截断时,例如

代码语言:javascript
复制
"xception [...]: For input string: "8080

而不是

代码语言:javascript
复制
Exception [...]: For input string: "8080"

你知道你在处理马车退货问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17929261

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档