A Conversation for The H2G2 Programmers' Corner

DOS commands in Java

Post 1

Din'Amarth

I'm pretty new to Java, and I'm looking for something that is equivilent to "shell" in basic. Any thoughts?


DOS commands in Java

Post 2

Terran

You mean Shell as in when you type shell it immediately gives a visual list of directory's and where you can have a list of program's which you can go to immediately?

I maybe thinking of the wrong thing, but when I programmed in QuickBASIC, thats what Shell did when I was working in a solely DOS based environment.

I don't think anything like that exists for Java. Not to the best of my knowledge anyway.

I think I'd need to know more about what you're trying to do.


DOS commands in Java

Post 3

Peet (the Pedantic Punctuation Policeman, Muse of Lateral Programming Ideas, Eggcups-Spurtle-and-Spoonswinner, BBC Cheese Namer & Zaphodista)

If it saves a little time, I could point out that Java runs in a "Virtual Machine", and only has access to data in its own "Sandbox". It's been specifically written so it can *never* access files or data outside the confines of the language itself. The upshot of this is, as far as I know, that it's impossible to pass filesystem-level commands from Java to the machine that is hosting it. This is a design feature of the language, not a bug - if you need to be able to read external files you need to be programming in a different language. smiley - geek


DOS commands in Java

Post 4

Ion the Naysayer

It's been specifically written so it can *never* access files or data outside the confines of the language itself.

This depends on what application is being developed - for browser-displayed applets this is (generally) true; for full-blown applications you can read and write files but you have to do it Java's way.

What DOS commands were you looking to execute? move, copy, dir, etc? I may be able to point you to the documentation for an equivalent Java class.


DOS commands in Java

Post 5

Peet (the Pedantic Punctuation Policeman, Muse of Lateral Programming Ideas, Eggcups-Spurtle-and-Spoonswinner, BBC Cheese Namer & Zaphodista)

smiley - yikes Heretic! smiley - yikes





smiley - laugh


DOS commands in Java

Post 6

Ion the Naysayer

I couldn't see an application programming language being very useful if it didn't have the capacity to read or write files.

smiley - smiley


DOS commands in Java

Post 7

Peet (the Pedantic Punctuation Policeman, Muse of Lateral Programming Ideas, Eggcups-Spurtle-and-Spoonswinner, BBC Cheese Namer & Zaphodista)

"An applet cannot ordinarily read or write files on the host that is executing it.

The JDK Applet Viewer actually permits some user-specified exceptions to this rule, but Netscape Navigator 2.0, for example, does not. Applets in any applet viewer can read files specified with full URLs, instead of by a filename. A workaround for not being to write files is to have the applet forward data to an application on the host the applet came from. This application can write the data files on its own host. See Working with a Server-Side Application for more examples."

The above is taken from Sun's security notes... smiley - geek

http://java.sun.com/docs/books/tutorial/applet/practical/security.html


DOS commands in Java

Post 8

Ion the Naysayer

No argument here but that only applies to applets. If the software will be an application there are fewer hoops to jump through for file access.


DOS commands in Java

Post 9

Peet (the Pedantic Punctuation Policeman, Muse of Lateral Programming Ideas, Eggcups-Spurtle-and-Spoonswinner, BBC Cheese Namer & Zaphodista)

Fair enough. smiley - smiley


Key: Complain about this post