aspose file tools*
The moose likes Servlets and the fly likes Call UNIX commands from JAVA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Call UNIX commands from JAVA" Watch "Call UNIX commands from JAVA" New topic
Author

Call UNIX commands from JAVA

Dmitriy Bar
Greenhorn

Joined: Jan 02, 2004
Posts: 5
Can I execute UNIX commands from JAVA program running under Windows?
Tim Baker
Ranch Hand

Joined: Oct 04, 2003
Posts: 541
If you want to run them on the local machine then no, not without some kind of UNIX emulator / shell. Does such a thing exist for windows?


Kim Jong II (North Korea's Dear Leader) said:Nuclear weapons don't kill people, people kill people.
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

Originally posted by Tim Baker:
If you want to run them on the local machine then no, not without some kind of UNIX emulator / shell. Does such a thing exist for windows?

Yes - there is Cygwin - http://www.cygwin.com/ - I've never tried calling any of its commands from Java, but Dmitriy could give it a try.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

Originally posted by Dmitriy Bar:
Can I execute UNIX commands from JAVA program running under Windows?

This doesn't make sense. The only time I can think this would be a good idea is if you are testing for deployment and don't have access to a Linux machine. Of course then I would question why you are developing for Linux but don't have access for a linux machine.
So what's the story morning glory?


GenRocket - Experts at Building Test Data
Dmitriy Bar
Greenhorn

Joined: Jan 02, 2004
Posts: 5
Guys,
what I meant was:
you have some kind of AWT or Swing GUI running on your local PC and you want to execute some commands on UNIX server(without openning some kind of UNIX emulator and connecting to the UNIX server) and have result from this execution back to your Java application.
OR maybe there is a way of executing Java application(AWT/Swing) under UNIX OS without openning X Windows etc.
Thanks.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

Dmitriy Bar wrote:

Hi.
What I meant was:
you run some kind of AWT or Swing GUI on your local PC and want to bring a result of running some commands on UNIX server back to the Java application
(without openning some UNIX emulators and connecting to UNIX manually).
Or how to run AWT or Swing application under UNIX OS without openning X Windows etc.?
Thanks.

If you are wanting to return results back from running a Unix command on a Unix machine but your code resides on a Windows machine, you are going to have to use RMI to invoke methods on the remote machine to execute the commands you are requiring.
You cannot run GUI applications in Unix without the X Windows System running. The X11 system is what allows widgets to be drawn on the screen. Without it, it is pure text. Unless you can write a nice little ASCII GUI in Java.
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Gregg wrote: If you are wanting to return results back from running a Unix command on a Unix machine but your code resides on a Windows machine, you are going to have to use RMI to invoke methods on the remote machine to execute the commands you are requiring.
Or any other protocol, really: HTTP/CGI, telnet, ssh, rsh, rlogin, web services, etc. etc. The important thing is that you need to send your command(s) to the remote machine, let it do its stuff, and return the result to you.
You cannot run GUI applications in Unix without the X Windows System running. The X11 system is what allows widgets to be drawn on the screen. Without it, it is pure text. Unless you can write a nice little ASCII GUI in Java.
http://www.pitman.co.za/projects/charva/


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

Originally posted by Frank Carver:
http://www.pitman.co.za/projects/charva/

That is cool. I actually could find a use for that. Thanks Frank!! Not to mention it is a good solution for this guys problem.
Dmitriy Bar
Greenhorn

Joined: Jan 02, 2004
Posts: 5
Thanks, Frank.
Did you try PJAToolkit?
Brian Pipa
Ranch Hand

Joined: Sep 29, 2003
Posts: 299
I have recently used the SSH tools from http://www.3sp.com in a big project and it works fabulously. If you have SSH access to the Unix box, it is a great solution - free and secure. There are some example java classes that come with it that show you how to do basic stuff like connect via SSH/SFTP with name/pass and with keys.
Brian


My Java Freeware:<br />MACCC - <a href="http://maccc.pipasoft.com" target="_blank" rel="nofollow">http://maccc.pipasoft.com</a><br />Nator - <a href="http://nator.pipasoft.com" target="_blank" rel="nofollow">http://nator.pipasoft.com</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Call UNIX commands from JAVA