2 Questions: java calling system commands? PERL vs Java?
1. Can you call system commands from a java program? If so, how?
For example, I want to write a simple program that tells me the time or date or even untar a file. It just never occured to me of doing that stuff before on Java. I know you can create that on a simple shell script...I'm just exploring new ways of doing stuff. 2. I'm between learning PERL or furthering in Java. My main turn off with Java is speed and the "classes". It's like you are creating small little programs inside your big program. It's a hassle. This is what I want to do: a) I want to have the speed of shell scripting for both executing and writing code. b) I want easy syntaxing. From what I read, PERL is what I'm looking for. But if I can do shell-scripting type of coding with Java, I'll stick with Java. By the way...Can you do GUI apps with PERL using QT or something? I mean, besides web based apps? Thank you guys, RandomX |
Uh, your java question is kind of hard.. for me seeing as how I'm not the most advanced Java person around, you should check out the Sytem class (http://java.sun.com/j2se/1.4.2/docs/...ng/System.html) I'm sure if there is something, it'd be in there... anyway, yes, perl can create gui's using QT, you have to download a library though! :) I think that's, hope I answered both your questions...
|
Check out the System.exec() function in the System class like zer0python said.
|
Can you give me a quick example on how to use System.exec() function in the System class?
For example, I want to untar the the file foo.tar. My system is linux 2.4.22 using BASH shell. Code:
public class UntarringFiles |
my guess would be more or less ->
Code:
|
I'm sorry. I'm a moron. I wasn't thinking. It's not System.exec, but rather Runtime.getRuntime().exec("command here");
Here's a link Sorry for the mental lapse. |
I got an error....any ideas what's going on?
Code:
$ javac UntarringFiles.java |
Another compiling error but now using your second suggestion....
Code:
UntarringFiles.java:6: unreported exception java.io.IOException; must be caught or declared to be thrown Code:
public class UntarringFiles |
put it in a try clause
Code:
|
It compiles ok. But I get a run-time error.
Code:
$ java UntarringFiles.java |
java UntarringFiles
you should not have the .java extension when you run it. |
oooops....my bad. I can't believe I missed that basic stuff.
it runs fine now.. complete code Code:
public class UntarringFiles |
Don't worry about it. I do it all the time, and I've been using java for a few years now. I'm glad it works.
|
Quote:
Do you know how to use PERL-TK or any similar PERL GUI development? my main concern with Java is speed. Speed writing it, running it, debugging it. But I kinda miss the GUI. Can you use QT-Designer or Kdevelop to make GUI stuff in PERL? any thoughts on that? any Better PERL GUI development tool? |
The main gui module for Perl is Tk. It's pretty decent.
Though i still prefer Java over Perl as a true programming language. Mainly because i'm an oop whore ;) |
All times are GMT -5. The time now is 12:25 PM. |