By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,143 Members | 1,855 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,143 IT Pros & Developers. It's quick & easy.

Calling a shell function

P: n/a
I'm creating a routine (not in a browser) to move multiple files on a daily
basis to a backup directory. It can be done easily by call shell functions
like 'mv file* newdir'.
I can't find any reference in the Java tutorial about accessing or using the
shell or system other than standard i/o. Does anyone have a clue on how to
pass a command to the shell to execute a program?

My other option is to write a shell script that calls a few minor Java
routines (such as creating date based filenames) and does most things in the
shell. I would need to pass multiple int and string variables both ways if
I did that.

Thanks, John.
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
John Bowling wrote:
I'm creating a routine (not in a browser) to move multiple files on a daily
basis to a backup directory. It can be done easily by call shell functions
like 'mv file* newdir'.
I can't find any reference in the Java tutorial about accessing or using the
shell or system other than standard i/o. Does anyone have a clue on how to
pass a command to the shell to execute a program?

My other option is to write a shell script that calls a few minor Java
routines (such as creating date based filenames) and does most things in the
shell. I would need to pass multiple int and string variables both ways if
I did that.

Thanks, John.


Hi,

I don't see why you should change between Java and shell. A unix shell
is very mighty and you can do backup jobs via shell and without java. I
use http://reoback.sf.net although trying to do everything else with Java ;)

Despite, if you want to call a shell command you can use
java.lang.Runtime and its exec-methods.

If you execute a Java program from shell you can parse its output to get
the information you want.

Patrick

Jul 17 '05 #2

P: n/a
If you are moving the files within the same filesystem, you can use the
Java File object to rename it like a Unix mv command.
See java.io.File.renameTo()

If you are going off the file system then you will have to do a copy and
delete. The copy would presumably be done using Buffered Streams. Be
careful not to ignore any exceptions since there could be an incomplete
copy and you'd then delete your source without a backup.

Constantine

John Bowling wrote:
I'm creating a routine (not in a browser) to move multiple files on a daily
basis to a backup directory. It can be done easily by call shell functions
like 'mv file* newdir'.
I can't find any reference in the Java tutorial about accessing or using the
shell or system other than standard i/o. Does anyone have a clue on how to
pass a command to the shell to execute a program?

My other option is to write a shell script that calls a few minor Java
routines (such as creating date based filenames) and does most things in the
shell. I would need to pass multiple int and string variables both ways if
I did that.

Thanks, John.


Jul 17 '05 #3

P: n/a
could you cause your java program to run FTP?
FTP supports both binary and ascii and is pretty fast

"CD Rasmussen" <Co*******************@comcast.net> wrote in message
news:P8********************@comcast.com...
If you are moving the files within the same filesystem, you can use the
Java File object to rename it like a Unix mv command.
See java.io.File.renameTo()

If you are going off the file system then you will have to do a copy and
delete. The copy would presumably be done using Buffered Streams. Be
careful not to ignore any exceptions since there could be an incomplete
copy and you'd then delete your source without a backup.

Constantine

John Bowling wrote:
I'm creating a routine (not in a browser) to move multiple files on a daily basis to a backup directory. It can be done easily by call shell functions like 'mv file* newdir'.
I can't find any reference in the Java tutorial about accessing or using the shell or system other than standard i/o. Does anyone have a clue on how to pass a command to the shell to execute a program?

My other option is to write a shell script that calls a few minor Java
routines (such as creating date based filenames) and does most things in the shell. I would need to pass multiple int and string variables both ways if I did that.

Thanks, John.

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.