• 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

Runtime.getRuntime().exec

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
 
Rancher
Posts: 280
VI Editor C++ Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 280
VI Editor C++ Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 27807
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic