【发布时间】:2018-01-31 06:26:52
【问题描述】:
我正在尝试执行以下链接中作为解决方案提供的命令:https://apple.stackexchange.com/questions/258020/why-does-find-certificates-have-some-missing 我正在使用 java 中的 processbuilder 执行命令,但由于某种原因,即使命令运行完美,我也无法从 stringbuffer 获取值在终端。 这是可能的java命令:
ArrayList<String> lcommands = new ArrayList<String>();
ArrayList<ArrayList<String>> lcommandsets = new ArrayList<ArrayList<String>>();
lcommands = new ArrayList<String>();
//lcommands.add("security find-identity -p codesigning -v");
// lcommands.add("security");
// lcommands.add("find-identity");
// lcommands.add("-p");
// lcommands.add("codesigning");
// lcommands.add("-v");
lcommands.add("security find-certificate -a -p codesign ~/Library/Keychains/login.keychain \\\n| awk '/-----BEGIN CERTIFICATE-----/ { cert = \"\" } \\\n{ cert = cert $0 \"\\n\" } \\\n/-----END CERTIFICATE-----/ { \\\nopenssl = \"openssl x509 -text -enddate -noout\"; \\\nprint cert | openssl; \\\nclose(openssl) \\\n}'");
// lcommands.add("find-certificate");
// lcommands.add("-a");
// lcommands.add("-p");
// lcommands.add("codesign");
//lcommands.add("~/Library/Keychains/login.keychain \\\n| awk '/-----BEGIN CERTIFICATE-----/ { cert = \"\" } \\\n{ cert = cert $0 \"\\n\" } \\\n/-----END CERTIFICATE-----/ { \\\nopenssl = \"openssl x509 -text -enddate -noout\"; \\");
// lcommands.add("~/Library/Keychains/login.keychain \\");
// lcommands.add("| awk '/-----BEGIN CERTIFICATE-----/ { cert = \"\" } \\");
// lcommands.add("{ cert = cert $0 \"\\n\" } \\");
// lcommands.add("/-----END CERTIFICATE-----/ { \\");
// lcommands.add("openssl = \"openssl x509 -text -enddate -noout\"; \\");
// lcommands.add("print cert | openssl; \\");
// lcommands.add("close(openssl) \\");
// lcommands.add("}'");
System.out.println();
lcommandsets.add(lcommands);
for (int i = 0; i < lcommandsets.size(); i++) {
Process process = null;
try {
ArrayList lruncommands = (ArrayList) lcommandsets.get(i);
ProcessBuilder lprocessbuilder = new ProcessBuilder(lruncommands);
// lprocessbuilder.directory(new File("/Users/"));
// lprocessbuilder.directory(new File("/Users/Admin/Library/Keychains"));
lprocessbuilder.redirectErrorStream(true);
process = lprocessbuilder.start();
try (BufferedReader bri = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
String line;
while ((line = bri.readLine()) != null) {
//System.out.println(line);
if (line.contains(":") && line.contains("(")) {
lcertname = line.substring(line.indexOf(":") + 1, line.indexOf("(")).trim();
lteamid = line.substring(line.indexOf("(") + 1, line.lastIndexOf(")")).trim();
String ltrim=line.trim().substring(line.indexOf(')')+1);
luuid=ltrim.substring(0,ltrim.indexOf(" "));
//System.out.println("");
ArrayList<String> lval=new ArrayList<String>();
lval.add(0, luuid);
lval.add(1, lcertname);
lkeys.put(lteamid,lval );
}
}
} catch (Exception e) {
e.printStackTrace();
}
所有注释行都是我尝试过的不同组合。如果有人知道如何拆分命令,那将非常有用。提前致谢。
【问题讨论】: