File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes RunTime.exec() and FTP Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "RunTime.exec() and FTP" Watch "RunTime.exec() and FTP" New topic
Author

RunTime.exec() and FTP

Judy Collins
Greenhorn

Joined: Oct 07, 2004
Posts: 20
Hi Guys,
On WinXP, I am using
String command ="cmd /c ftp -v -s: cmd.txt "
Runtime.getRuntime().exec(command);
....
.....

FTP Command is supposed to get a file from remote server, but as long as my program is running it does not get the file. Once I kill my program all of a sudden file pops up.
But if I leave my program running file never shows up.

Any ideas, help is greatly appreciated.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12268
    
    1
It appears that you have not provided for consuming the stdout and stderr streams from the process that your exec() creates. The ftp program is probably trying to write something - since you don't read it, the program hangs.
Bill
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
In other words, you might need to do something like this:




It's like milking a cow. She's all pent-up, wanting that release, and if you don't draw it out of her, she can get quite ornery and not behave the way you'd like!

Ok, that's my first and maybe last ranch analogy here at JavaRanch...
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12268
    
    1
To continue Stephans analogy - his code only pulls on one teat - the stdout stream. If the program also write to std err, you need to write a separate Thread to suck on that teat too. - ewww
Bill
Judy Collins
Greenhorn

Joined: Oct 07, 2004
Posts: 20
Thank you guys!
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: RunTime.exec() and FTP
 
Similar Threads
Question About Usin FTP Dos Command in JAVA
Upload a file to unix and invoke a java method
Need help to write Client/Server java socket program to transfer files between client/server
FTP Issue
standalone application question