Adding java variable to batch file -


here's updated code. button being clicked in class made separate form java class provided. know says ping (disregard that, i'm using button testing purposes) don't see how reference each other process p line of code provided. think?

jbutton btnpingcomputer = new jbutton("ping");          btnpingcomputer.addactionlistener(new actionlistener() {              public void actionperformed(actionevent arg0) {                  string line;                 bufferedwriter bw = null;                 bufferedwriter writer =null;                 try {                     writer = new bufferedwriter(new filewriter(tempfile));                 } catch (ioexception e1) {                     // todo auto-generated catch block                     e1.printstacktrace();                 }                 string linetoremove = "ou=workstations";                 string s = null;                  process p = null;                 try {                     p = runtime.getruntime().exec("cmd /c start c:\\computerquery.bat computername");                 } catch (ioexception e1) {                     // todo auto-generated catch block                     e1.printstacktrace();                 }                 try {                      p = runtime.getruntime().exec("c:\\computerquery.bat");                  } catch (ioexception e) {                      // todo auto-generated catch block                      e.printstacktrace();                  }                 stringbuffer sbuffer = new stringbuffer(); // new trial                 bufferedreader in = new bufferedreader(new inputstreamreader(p                         .getinputstream()));                  try {                      while ((line = in.readline()) != null) {                          system.out.println(line);                          textarea.append(line);                         textarea.append(string.format("  %s%n", 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();                         system.out.println(commonname);                     }                  } catch (ioexception e) {                      // todo auto-generated catch block                      e.printstacktrace();                  } catch (invalidnameexception e) {                     // todo auto-generated catch block                     e.printstacktrace();                 }                  {                     try {                         fw.close();                      }                      catch (ioexception e) {                         // todo auto-generated catch block                         e.printstacktrace();                     }                 }                  try {                      in.close();                  } catch (ioexception e) {                      // todo auto-generated catch block                      e.printstacktrace();                  }              }          }); 

add parameter java program :

process p = runtime.getruntime().exec("cmd /c start c:\\batfile.bat computername");
this pass parameter_to_pass batch file.

for situation code should work well:

/* java program copies value jtextfield, adds     predifined value  , send command-line parameter. these happens if click     jbutton */   import javax.swing.*; import java.awt.*; import java.awt.event.actionevent; import java.awt.event.actionlistener;  public class cmdjavatest extends jframe { jtextfield jtextfield1 = new jtextfield(20); jbutton jbutton1 = new jbutton("click"); jlabel jlabel1 = new jlabel();  public cmdjavatest() {     super("cmdjavaparameterpass");      getcontentpane().setlayout(new flowlayout());      getcontentpane().add(jtextfield1);     getcontentpane().add(jbutton1);     getcontentpane().add(jlabel1);     jbutton1.addactionlistener(new actionlistener()     {         public void actionperformed(actionevent e)         {             sendparam();         }         });         setsize(300, 170);         setvisible(true);     }    public void sendparam(){       try{             string val = "computer"+jtextfield1.gettext(); //put whatever want pass prefix in place of "computer"             jlabel1.settext(val);             process p ;             p = runtime.getruntime().exec("cmd /c start c:\\batfile.bat "+val+"");         }         catch(exception e){             e.printstacktrace();         }   }    public static void main(string argv[]) {     new cmdjavatest();   } } 

use test batch file content
@dsquery computer -name %1 pause

but must see how use processbuilder.

thanks, hope helps


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -