0

我有一个这样的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 程序。我应该为此做些什么。谢谢。

4

2 回答 2

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 程序中。

于 2013-02-07T04:57:17.897 回答
1

检查参数:

public static void main(String[] args)
于 2013-02-07T04:53:06.530 回答