• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Call UNIX commands from JAVA

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can I execute UNIX commands from JAVA program running under Windows?
 
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Dmitriy Bar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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/
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Frank.
Did you try PJAToolkit?
 
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic