This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Runtime.getRuntime().exec

 
Eung maeng
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 272
C++ Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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/
 
Eung maeng
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stefan,
where can I see a sample .sh for ftp? if so, please let me know.

thanks
 
Anand Hariharan
Rancher
Posts: 272
C++ Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18094
48
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic