【发布时间】:2017-03-10 07:05:08
【问题描述】:
需要运行netstat -n |找到“:3389” |使用 Java 运行时查找“ESTABLISHED” 命令。
尝试像:Runtime.getRuntime().exec(cmd);,但如果我们有 |,我们就不能这样做。 (管道) 在我们的命令中。
我找到了 linux 命令,我们可以像这样构造:
String[] cmd = {"/bin/sh", "-c", "grep -c 'Report Process started' /path/to/server.log"};
Runtime.getRuntime().exec(cmd);
但我需要windows,请告诉我我们该怎么做?
【问题讨论】:
-
与stackoverflow.com/questions/15464111/… 的答案相同,尽管我更喜欢 user1121883 的答案
标签: java windows powershell runtime.exec