Tim Cooke wrote:Even path separators vary between platforms, "/" on Linux and "\" on Windows.
However, it is a standard that "/" works as a path separator for Java in ALL operating systems, so that's not a problem.
Incidentally, in Linux, an SMB shared file path is in the form "//hostname/sharename/dirname/dirname/filename". Even outside of Java, since backslashes are perilous to Unix-style users.
Yes, there is a Java library for working with CIFS file sharing.
And no, I don't recommend using Runtime.exec() to execute a series of commands and especially not with redirects. Command-line Redirects and piping are a shell function, and I'm pretty sure that Runtime.exec does not spawn a shell automatically. For one thing, there's only about 8 different shells available to Linux users, so you'd have to indicate which one to use. Put the commands into a shell script and exec() something like "
/usr/bin/sh /absolute/path/to/my/script".
Finally, to capture
stdout/
stderr or set
stdin on Runtime.exec() is a lot messier, if I recall, than in that example. You basically have to pre-allocate Java Streams and feed them in as part of the exec(). Then you have to have code to do something with what comes out of (or goes into) the streams.
And welcome to the Ranch, Alexander!