1

I used cshell/tcshell before and than turned to python.

Now I am going to integrate all my shell scripts, GUI, database, webpages together. Python is good at most of works, but it's relatively weak at GUI, general performance and third partu libraries.

So I am going to try java as my main development language. Is it good at shell interactive programming, process control, etc.?

3 Answers 3

3

Java by itself may not be the greatest shell language, because of slow boot times, lack of built-in libraries to work with the operating system, commands and files (I mean, there is even no way to copy a file in Java without resorting to creating two input and output streams and piping the data, yack!).

However! There are plenty of JVM-based languages like, JRuby(ruby), Rhino(javascript), Jython(python), Groovy or Grash, Bean-shell, etc. that work like shell languages and can run other Java-written programs. I would recommend you have a look at Grash that is probably exactly what you need.

Some of those language even have a way to pre-load JVM runtime to speed-up boot time (e.g Nailgun for JRuby), so that can solve the slow boot time problem. Also see this post for using Ruby(JRuby) as a shell language.

Sign up to request clarification or add additional context in comments.

6 Comments

I mean, there is even no way to copy a file in Java without resorting to creating two input and output streams and piping the data, yack! This is not true: FileChannel.transferTo. Either way, Main issue w/ java for a shell script stuff is that the JVM starup takes quite a bit time. The main culprit is of course the disk, though.
FileChannel.transferTo is not any better. You still have to create two file handles for source and destination files and manually loop over it to transfer the data. This is a lot of code for something as simple as copy. Compare it to one line: FileUtils.copyFile(file1, file2) using apache's commons.io library. The boot time is slow, but, as I have mentioned, you can defeat that with Nailgun, which can preload the JVM once and allow you to reuse it every time you launch your program. Nailgun should work for any JVM-based language.
I don't see the problem, you can either use the apache library or have your own class/method. As for Nailgun (just checked the source code): it's a bit of software (dedicated server) that can speed up some commands in case multiple involations. If doesn't guard static data, nor long dormant threads, so it will take a very well behaved 'plugins' that clean up everything, incl file handles. Running a separate process saves all the problem of possible errors, unclosed handles, memory leaks, etc.
side note, jdk7 has a single line copy (and move) utility. download.java.net/jdk7/docs/api/java/nio/file/…
@bestsss I meant to say that Java has no built-in functions for every-day shell scripting tasks out-of-the-box. Well, you'd just have to use a library like commons.io, and that solves that, I agree. As for Nailgun, I wouldn't use it in production for the reasons you've described, but it's good for developing and testing scripts. Boot time will also depend on your machine. On my desktop machine JVM starts in less than tenth of a second in client mode. Groovy, JRuby and the like take significantly longer though, but whether that's really a hindrance to you will depend you your needs.
|
1

Booting JVM is usually slow and eats considerable memory (compared to native apps) So it is not good for running many(parallel) small applications(processes) that start and die often. ... if that was your intention

Comments

0

I wrote jpad to allow running java "shell scripts" and interactive snippets while also providing nice visualization of the results. This shows what I mean:

JPad Java REPL

To copy a file using this as a scripting language you would use: http://jpad.io/example/1I/fileio

final File file = new File("outt.csv");
Object o = new int[] {1,2,3};
JPad.writeCsv(o, file);
java.nio.file.Files.copy(file.toPath(), Paths.get("copy.csv"));

Which you can also run from the command line as:

> more fileio.jpad
final File file = new File("outt.csv");
Object o = new int[] {1,2,3};
JPad.writeCsv(o, file);
java.nio.file.Files.copy(file.toPath(), Paths.get("copy.csv"));
> jpad fileio.jpad
> dir
29/04/2017  13:30    <DIR>          .
29/04/2017  13:30    <DIR>          ..
29/04/2017  13:30                16 copy.csv
29/04/2017  13:30               160 fileio.jpad
29/04/2017  13:30                16 outt.csv

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.