开发者

Use java as a linux shell script language?

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 3rd part libraries.

So I am going to try java as my main development language. Is it good at shell interactive 开发者_如何学Pythonprogramming, process control, .. etc?

Thanks a lot.


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.


Take a look at Groovy if you want to use the Java platform as a scripting language.


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


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:

Use java as a linux shell script language?

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜