Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

getRuntime().exec() vs cmd prompt  RSS feed

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the difference between getRuntime().exec("my command") and executing "my command" from a regular command prompt?

I'm trying to open ms access with a specific file, which I can do a few different ways from a command prompt, but I keep getting a warning when I try to do this from java that Access can't open it. Any suggestions?

exact warning - Ms Access is unable to open the data access page. The file you attempted to load was not recognized as HTML....

It can find the file. If I use an incorrect name it gives me a different warning.
 
Rancher
Posts: 43009
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Runtime.exec(String) is very picky about the command line parameters, in particular if they contain characters that need to be escaped. I find it much less troublesome to use the Runtime.exec(String[]) variant.

By the way: Access can open HTML files? You learn something new every day...
 
Rich Stepanski
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i guess it can. I just tried cause I was wondering. It tries to connect to setup some connection to a DB, but it will open the html file.
 
Ranch Hand
Posts: 657
Clojure Spring VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's some good reading...

Navigate yourself around pitfalls related to the Runtime.exec() method
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also go to a command window and try CMD /? and COMMAND /?. There are some things that require these commands when you go through runtime exec.

Other gotchas ... some commands hang up if you're not reading stdout and stderr. Look into the getWhatever methods on the object you get from exec.

You can open files with the RUNDLL32 command. Google for that one for details. It's just like clicking a file in Explorer or entering a filename like a command. Try "myspreadsheet.xls" as a command for fun. For a file that exists, of course.
 
Tick check! Okay, I guess that was just an itch. Oh wait! Just a tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!