简体   繁体   English

通过java程序执行shell脚本

[英]Executing shell script through java program

I am trying to execute shell script through java program but the script is not executing completely.我正在尝试通过 java 程序执行 shell 脚本,但脚本没有完全执行。

Script:脚本:

shell.sh ./MetaMatch.sh songsMetaData.json > songsResult.json shell.sh ./MetaMatch.sh songMetaData.json > songResult.json

Though it is printing songsResult.json file but empty.虽然它正在打印 songResult.json 文件但为空。

You can use java ProcessBuilder to execute shell script in local machine.您可以使用 java ProcessBuilder 在本地机器上执行 shell 脚本。 You can find lot of example in google one of them is http://esudharaka.blogspot.in/2012/06/executing-shell-script-from-java-class.html .你可以在谷歌找到很多例子,其中之一是http://esudharaka.blogspot.in/2012/06/executing-shell-script-from-java-class.html If shell script is in remote host than you have to use libraries like Jsch如果 shell 脚本在远程主机中,那么你必须使用像Jsch这样的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM