When running a command line command via ProcessBuilder (specifically "GetMac /s") if it throws an error or returns normally and I can read the error or the MAC address that it returns but if it prompts the user input (some pc's on the network require a password when using getmac) the process will just hang waiting for the password.
Here is what the command does when run from command line:
Here is the code I'm using for the process:
package testing;
import java.io.IOException;
class test1 {
public static void main(String[] args){
String hostName = "testpc";
ProcessBuilder builder = new ProcessBuilder("getmac", "/s", hostName, "/nh");
builder.inheritIO();
try {
Process proc = builder.start();
} catch (IOException e) {
e.printStackTrace();
}
}
}
The reason I need the mac is for making a wake on lan program and want to automatically get any new pc's mac addresses when they're detected so the user doesn't have to enter it manually. so if you know a better way of getting the MAC of a remote pc by all means let me know and I'll use that instead.
I realize java probably isn't the best language to be using for this but it's the only one I know at the moment and this is just fun little project for my downtime at work.
**Edit: if it requries a password I just want to ignore that PC and kill the process and move on to the next PC
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…