Re: runtime.exec() How to copy all files ?



k4 wrote:

Witam

My class:

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;


public class test {

public static void main( String [] args ) {
try{
Runtime runtime = Runtime . getRuntime();

String cmd ="/bin/cp /home/k/java/* /var/www/k/";
System.out.println(cmd);
Process process = runtime.exec(cmd);
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader bfr = new BufferedReader(isr);
String line;

while ( ( line = bfr . readLine() ) != null ) {
System.out.println(line);
}
}catch(Exception e){
}

}
}

If I use "*" to copy all files, then command doesn't work why? If I try
copy single file then everything is ok.
String cmd ="/bin/cp /home/k/java/single.txt /var/www/k/";

Because "*" is only special to the shell, and you are not invoking a shell. In
your case the executable /bin/cp would try to copy a file called "*", and there
isn't one.


How to copy all files ? :/a

Invoke a shell:

String[] cmd ={"/bin/sh", "-c", "/bin/cp /home/k/java/* /var/www/k/"};

--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@xxxxxxxxxxxx
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
.



Relevant Pages

  • Memorial Day report
    ... the pieces I'd fused with my bare match used a double string (parallel ... My film cannister shell was a test of my first use of homemade piped ... One of the stars distinctly changed from ... I get a good fire seal and fit to the mortar without noticeably ...
    (rec.pyrotechnics)
  • Re: Off center spiking
    ... 32 - The procedure is the same for any diameter shell. ... strands of cotton, laying flat next to each other both vertically ... pick a guide mark on top and wind to the bottom matching ... shell from what appear to be two separate strands of string. ...
    (rec.pyrotechnics)
  • Re: Off center spiking
    ... Your video is worth 1000 times that. ... 32 - The procedure is the same for any diameter shell. ... strands of cotton, laying flat next to each other both vertically ... shell from what appear to be two separate strands of string. ...
    (rec.pyrotechnics)
  • Re: TRUE is 0 is FALSE
    ... The shell is innumerate, so it is silly to suggest that its true ... In conditionals, a nonempty string is true, empty string is false. ... A number behaves as boolean ...
    (comp.unix.shell)
  • comp.unix.shell FAQ - Answers to Frequently Asked Questions
    ... This FAQ list contains the answers to some Frequently Asked Questions ... It spells "unix" in lower case letters ... The other level is how to write shell scripts. ... if the string being echoed wasn't built into the script ...
    (comp.unix.shell)