当我尝试用进程 ID 填充二维数组时出现 nullpointerexception,它是二维的,因为每个系统都有无限的 PID 列表,我最终需要将其返回到我的主代码(现在设置为 void,因为只是一个原型测试功能)。
任何想法都会很棒
private void testfunctionA (List<String> additionalPC) {
// A 2d array that will contain a list of pids for each system - needs to be strings and not integers
String[][] pidCollection = new String[additionalPC.size()][];
// Go through one system at a time
for (int i=0; i < additionalPC.size(); i++) {
// Get pids for apple per system
String listofpids = Driver.exec("ssh " + additionalPayloads.get(i) + " ps -ef | grep -i apple | grep -v \"grep -i apple\" | awk \\' {print $2}\\'");
// Works ok for printing for one system
System.out.println(listofpids);
// put the list of pids into a string array - they are separated by rows
String[] tempPid = listofpids.split("\n");
// Put the string array into the 2d array - put this fails with a NPE
for (int j=0; j < tempPid.length; j++) {
pidCollection[i][j] = tempPid[j];
}
System.out.println(pidCollection);
}