java - Launch process (file) within from a .jar script -


i'm trying figure out how example run file/app located on desktop. in case, test everything, created batch file called test.bat , inside there command:

@echo msg * hello 

which pop-up message box.

this should launched within netbeans jbutton, have:

private void jbutton1actionperformed(java.awt.event.actionevent evt) {                                                       // todo add handling code here:          runtime rt = runtime.getruntime();         process pr = rt.exec("msg * hello");       } 

however every time hit button, nothing happens.

in addition, read several posts here on stackoverflow, still cant figure out i'm doing wrong, since error message adding lines runtime rt = runtime.getruntime(); process pr = rt.exec("start test.bat");

for line:

process pr = rt.exec("start test.bat"); 

which says:

unreported exception ioexception; must caught or declared thrown

how can launch (maybe otherwise) test.bat file pushing button?

and have read other posts none of them talking ioexceptions.

again! there solution yet, have found error, stop marking post duplication....

this got try catch, working now.

private void jbutton1actionperformed(java.awt.event.actionevent evt) {                                              // todo add handling code here:     runtime rt = runtime.getruntime();     try {         process pr = rt.exec("msg * hello");     } catch (ioexception ex) {         logger.getlogger(mainframe.class.getname()).log(level.severe, null, ex);     } }  

this working code:

string programfilesx86= system.getenv("programfiles(x86)");   private void jbutton1actionperformed(java.awt.event.actionevent evt) {                                                  // todo add handling code here:         runtime rt = runtime.getruntime();         try {              process pr = rt.exec("cmd /k start \"\" \""+programfilesx86+"\\folder\\test.exe\" " );         } catch (ioexception ex) {             logger.getlogger(mainframe.class.getname()).log(level.severe, null, ex);         }     }   

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -