• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Runtime.getRuntime().exec

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried the following it works

Runtime.getRuntime().exec("C:\\Program Files\\Microsoft Office\\OFFICE11\\WINWORD.EXE")

But when i try

Runtime.getRuntime().exec("WINWORD.EXE")

I am getting error:

java.io.IOException: Cannot run program "WINWORD.EXE": CreateProcess error=2, The system cannot find the file specified


Anyone has any clue on this? Do i always have to give full path?

Regards
Venkat
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

No, you don't have to give the full path, but your PATH environment variable needs to point to the directory in which WINWORD.EXE resides. In general, if you can bring up a CMD window and type WINWORD.EXE and have Word launched, then Runtime.exec() would work without the full path -- but it CMD can't do it, Java can't, either.

This is not an advanced Java programming question, so I'm going to slide this over to our intermediate forum.
 
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Venkatesh ,

when you execute the bewlow code

winword.exe either needs to be in ssystem32 folder ( 0r) any folder which is in path ( in system configuration ) .
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Along the same lines..

I have a series of SQL commands that are performed on a database table. This string is currently called within a batch file and I would like to execute it within java instead.

Runtime rt = Runtime.getRuntime();
String cm[] = {�cmd�,�mysql -h host -u user -p pass database<�c:\\generate.sql��};
Process p =rt.exec(cm);

No errors are thrown but no updates take place. Am I just missing a step or have I got some syntax wrong?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's generally less error-prone to use the exec(String[], String[]) call than the exec(String, String[]) variety. This article talks about everything that can go wrong with Runtime.exec.
 
reply
    Bookmark Topic Watch Topic
  • New Topic