[英]Running Command line commands within Java
Is it possible to run this cmd line command curl ipinfo.io
within java?是否可以在
curl ipinfo.io
内运行此 cmd 行命令 curl?
I want to then pull the lat and long or "loc" from it afterwards.之后我想从中拉出经纬度或“loc”。 Thanks
谢谢
You can use您可以使用
var p = Runtime.getRuntime().exec("curl ipinfo.io")
And read the output like:并阅读 output,如:
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(p.getInputStream()))) {
return bufferedReader.lines().collect(Collectors.toList());
} catch (IOException e) {
e.printStackTrace()
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.