The most intelligent Java IDE
[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Reply Bookmark it! Watch this topic JavaRanch » Forums » Engineering » Linux / UNIX
 
RSS feed
 
New topic
Author

Runtime.getRuntime().exec

Eung maeng
Ranch Hand

Joined: Feb 10, 2002
Messages: 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
Ranch Hand

Joined: Aug 22, 2006
Messages: 182

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
Messages: 1847

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
Messages: 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
Messages: 68

Stefan,
where can I see a sample .sh for ftp? if so, please let me know.

thanks
Anand Hariharan
Ranch Hand

Joined: Aug 22, 2006
Messages: 182

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

"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." -- Antoine de Saint-Exupery
Tim Holloway
Bartender

Joined: Jun 25, 2001
Messages: 7766

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.

If a low price is more important to you than getting good value for your money, you're not as prosperous as you think you are.
 
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Engineering » Linux / UNIX
 
RSS feed
 
New topic
hibernate profiler