aspose file tools*
The moose likes Java in General and the fly likes Executing Unix Commands/Shell Scripts from Windows Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Executing Unix Commands/Shell Scripts from Windows" Watch "Executing Unix Commands/Shell Scripts from Windows" New topic
Author

Executing Unix Commands/Shell Scripts from Windows

Vinod Pushpangathan
Greenhorn

Joined: Oct 20, 2007
Posts: 3
Hi,

I am a new-bie to Java.
So please excuse me for my mistakes.

I have a requirement wherein I need to execute Unix commands/shell scripts
)eg: copying directories, making tar files, executing shell scripts on Unix)
from windows application as the application is developed and running on Windows platform.(Oracle Forms)

Please let me know how do I go about doing it. (Guess I need to use Java here). Appreciate your help.

Thanks
Vinod
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14144
    
  18

Welcome to JavaRanch.

Have a look at class java.lang.Runtime. It contains exec(...) methods which you can use to run other programs from your Java application. Here's an article with examples. There are some potential pitfalls that can happen when you use that, however. See: this JavaWorld article.

You can also use class ProcessBuilder. See this article.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Out of the box, even Java can't execute unix shell scripts on windows.

Take a look at cygwin: http://www.cygwin.com/


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Doug Slattery
Ranch Hand

Joined: Sep 15, 2007
Posts: 294
Hi Vinod,

It sounds like you want to execute Unix commands on Windows as opposed to using Windows to remotely execute commands on a Unix server?.?.

For the former, there are public domain Unix command line utilities that have been ported to DOS/Command Prompt. For the latter I would recommend doing some google'ing for rsh (remote shell) for Windows.

Hope this helps...
Aloha,
Doug

-- Nothing is impossible if I'mPossible
Vinod Pushpangathan
Greenhorn

Joined: Oct 20, 2007
Posts: 3
Thanks a lot for the replies.

I still couldn't figure out how using exec I would be able to invoke unix shell scripts residing on unix box from windows. How am I supposed to pass the unix userid and password to initially connect to the unix box using exec.

I guess, if I am not wrong, servlets should be the answer as I need to have something residing on the unix box, which I can call from windows, which would do the trick for me.

Appreciate if someone can throw light on this.
Doug Slattery
Ranch Hand

Joined: Sep 15, 2007
Posts: 294
Hi Vinod,
Originally posted by Vinod Pushpangathan:
Thanks a lot for the replies.

I still couldn't figure out how using exec I would be able to invoke unix shell scripts residing on unix box from windows. How am I supposed to pass the unix userid and password to initially connect to the unix box using exec.

I guess, if I am not wrong, servlets should be the answer as I need to have something residing on the unix box, which I can call from windows, which would do the trick for me.

Appreciate if someone can throw light on this.


Now that that's clarified,
I would recommend doing some google'ing for rsh (remote shell) for Windows.


That's probably the easiest way if you're not in a secure environment. You can use exec to call the remote shell executable on Windows, which will forward the shell script command to the Unix server.

Hope this helps...
Aloha,
Doug

-- Nothing is impossible if I'mPossible
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Executing Unix Commands/Shell Scripts from Windows