获取shell脚本到java的值
我有一个这样的shell脚本获取shell脚本到java的值,java,shell,Java,Shell,我有一个这样的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..."
#!/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
现在我希望java程序的$s值。我该怎么办。谢谢。检查参数:
public static void main(String[] args)
检查参数:
public static void main(String[] args)
这个
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();
无论您使用echo在shell脚本中输出什么,都将在java程序中结束。这
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();
无论您用
echo
在shell脚本中输出什么,都将在java程序中结束。我只想插入java应用程序中的登录数据库。也许您可以提供更多的解释。您只是想用Java编写这个程序的等价物吗?或者,您是否希望专门运行此脚本并用Java捕获输出?请提供更多信息。我只想插入java应用程序的登录数据库。也许您可以提供更多的解释。您只是想用Java编写这个程序的等价物吗?或者,您是否希望专门运行此脚本并用Java捕获输出?请提供更多信息。