Is it possible to store the result of the execution of a command from java in a variable of type string? I've tried it this way but the output of stdInput.readLine () is always NULL, something I'm doing wrong. Another question is whether it is possible to concatenate the result of the execution of the command1 as I am doing in command2, by entering the variable in the middle of the string of the command? The code is as follows:
public class PDOFinder{
//PdoFinder constructor
public PDOFinder(){
}
//variables to store device data
static String webcamPDOName = null;
static String webcamDeviceID = null;
public static void main(String[] args) throws IOException{
try{
String output = null;
String output2 = null;
String[] command = new String[3];
command[0] = "cmd.exe";
command[1] = "/c";
command[2] = "C:\Users\user1\Desktop\devcon.exe find =image | findstr USB\VID*";
Process process1 = Runtime.getRuntime().exec(command);
InputStreamReader input = new InputStreamReader(process1.getInputStream());
BufferedReader stdInput = new BufferedReader(input);
System.out.println("salidaaa: "+stdInput.readLine());
if((output=stdInput.readLine()) != null){
webcamDeviceID = stdInput.readLine();
}
System.out.println(webcamDeviceID);
String[] command2 = new String[3];
command2[0] = "cmd.exe";
command2[1] = "/c";
command2[2] = "wmic path Win32_PnPSignedDriver where 'deviceid="+webcamDeviceID+"' get pdo";
Process process2 = Runtime.getRuntime().exec(command2);
InputStreamReader input2 = new InputStreamReader(process2.getInputStream());
BufferedReader stdInput2 = new BufferedReader(input2);
if((output2=stdInput2.readLine()) != null){
webcamPDOName = stdInput2.readLine();
}
System.out.println(webcamPDOName);
}
catch(Exception e){
System.out.println("Exception: "+e);
e.printStackTrace();
}
}
}