GeeCON Prague 2014*
The moose likes Linux / UNIX and the fly likes Runtime.getRuntime().exec Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Runtime.getRuntime().exec" Watch "Runtime.getRuntime().exec" New topic
Author

Runtime.getRuntime().exec

Eung maeng
Ranch Hand

Joined: Feb 10, 2002
Posts: 68
Could you please explain how to fix the problem from unix?

Process process = Runtime.getRuntime().exec("cmd.exe /c start \home\ftp.bat")

when i run this comman in unix, how can I use for "cmd.exe /c start" with exec(...)

thanks,
Anand Hariharan
Rancher

Joined: Aug 22, 2006
Posts: 257

cmd.exe is the command interpreter in Windows. There is no requirement for any of the UNIX shells to have an extension such as .EXE. No flavour of UNIX or no distro of Linux that I know of, bundle any windows emulator with the name cmd.exe.

Further, a batch file such as ones with .BAT typically contain a sequence of DOS commands.

Trying to run a batch file within a command interpreter in a Non-Windows environment is guaranteed to fail.

Telling us what exactly you are trying to do might help.

- Anand


"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." -- Antoine de Saint-Exupery
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

You could write:

and rewrite ftp.bat to ftp.sh first.

But maybe you'll find a pure java and therefore portable solution in the apache/commons project:
http://commons.apache.org/net/


http://home.arcor.de/hirnstrom/bewerbung
Eung maeng
Ranch Hand

Joined: Feb 10, 2002
Posts: 68
Thanks guys,
what I am trying to do in unix(qshell). I need to execute this batch file by Unix-qshell(.sh). However, qshell script complaint to cmd -d start.
Thus, i couldn't execute.

At this time, I will try to make .sh rather than .bat with /bin/bash

thanks for help,
Eung maeng
Ranch Hand

Joined: Feb 10, 2002
Posts: 68
Stefan,
where can I see a sample .sh for ftp? if so, please let me know.

thanks
Anand Hariharan
Rancher

Joined: Aug 22, 2006
Posts: 257

If your BAT file isn't too big, and if considerations like IP are moot, then suggest you post the contents of your BAT file. It shouldn't be too difficult to write something equivalent in bash.

That said, you should seriously consider Stefan's advise of using a Java solution. After all, you are running into this problem because of a cross-platform issue of trying to run something in UNIX that should be run on Windows. Performing whatever is being done in the batch file from within Java should obviate any platform considerations.

- Anand
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16095
    
  21

Originally posted by Paul Maeng:
Stefan,
where can I see a sample .sh for ftp? if so, please let me know.

thanks


If all you really want to do is send/receive file(s) via FTP, there's a very nice FTP library available from the jakarta.apache.org website. It will allow your Java app to connect to one or more FTP servers and do just about anything that you could from an FTP command shell.

It's also integrated into a larger universal filesystem project that pretty much allows apps to talk to all sorts of data connections, including Windows shares, Unix nfs, and whatever else you can think of.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
GeeCON Prague 2014
 
subject: Runtime.getRuntime().exec