我有一个方法允许我将部分计算机名称键入jtextfield并通过jbutton提交。 cmd提示符成功提供了完整的计算机名称。因此,如果我键入111255,命令提示符将输出coud111255。查询我使用(@dsquery computer -name *%1) 这部分效果很好。我的问题是从批处理文件中提取完整的计算机名称并将其分配给java变量。我试图将完整的计算机名称附加到textArea,但它只是从这里提取硬编码值:
字符串dn =" CN = FDCD111304,OU =工作站,OU = SIM,OU =帐户,DC = FL,DC = NET&#34 ;;)
有关如何将完整的计算机名称附加到textArea的任何建议吗?
sendParam()将一半的计算机名称传递给批处理脚本以查找完整的计算机名称。
public static void sendParam(){
try{
String val = MISControlPanel.textField.getText(); //Put whatever you want to pass as a prefix in place of "Computer"
jLabel1.setText(val);
Process p ;
p = Runtime.getRuntime().exec("cmd /c start c:\\computerQuery.bat "+val+"");
}
catch(Exception e){
e.printStackTrace();
}
}
StringBuffer sbuffer = new StringBuffer();
BufferedReader in = new BufferedReader(new InputStreamReader(p
.getInputStream()));
try {
while ((line = in.readLine()) != null) {
System.out.println(line);
//textArea.append(line);
String dn = "CN=FDCD111304,OU=Workstations,OU=SIM,OU=Accounts,DC=FL,DC=NET";
LdapName ldapName = new LdapName(dn);
String commonName = (String) ldapName.getRdn(ldapName.size() - 1).getValue();
textArea.append(String.format(" %s%n", commonName));
//textArea.setText(ComputerQuery.val);
selectedComputerFromAD.setText(commonName);
selectedComputerFromAD.setFont(new Font("Tahoma", Font.BOLD, 14));
selectedComputerFromAD.setForeground(Color.RED);
selectedComputerFromAD.setBounds(349, 84, 102, 19);
frame.getContentPane().add(selectedComputerFromAD);
}
ComputerQuery.sendParam();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (InvalidNameException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} finally
{
try {
fw.close();
}
catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
try {
in.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
ComputerQuery.sendParam();
}
});