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 :
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555