我有这样的shell脚本。
#!/bin/sh
s=$1
pro=`ps -ef | grep $s | grep -v grep | grep -v test3.sh`
pro1=`ps -ef | grep $s | grep -v grep | grep -v test3.sh | wc -l`
echo $pro
echo $pro1
if [ $pro1 -eq 0 ]
then
echo "Service $s is DOWN..."
echo "Service $s is DOWN..." >> processlogs.txt
echo "Starting Service $s..."
echo "Starting Service $s..." >> processlogs.txt
java -jar clientApplication.jar "$s" &
exit 0
else
echo "Service $s is Running..."
echo "Service $s is Running..." >> processlogs.txt
fi
现在我想要$ s的值到java程序。我该怎么做呢感谢。
答案 0 :(得分:3)
此...
Process p = Runtime.exec("myExeOrShellScript");
BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = r.readLine())!=null) {
// got the output in 'line' do something with it
}
r.close();
无论你在shell脚本中使用echo
抽出的内容都将在java程序中结束。
答案 1 :(得分:1)
检查args:
public static void main(String[] args)