External copy in java

I want to copy the content of a directory to another one, with the external copy command on a UNIX system
Process p = Runtime.getRuntime().exec("cp " + f1 + " " + f2);
So far it works with single files. But it doens't work with "*.*". The same command runs directly on the UNIX command line. There must be a problem with "*". Does anybody have an idea?

The "*" is expanded by the UNIX shell, not by the cp command. When you run a program using Runtime.exec(), you are running the program directly, not using the shell.
Why are you using a system command to perform a file copy anyway? More control for your program can be gained by performing the copy using Java functions.
To copy all the files in a directory, you could use the functions of the File class to get a directory listing and perform individual file copies, or you could change the exec to run the cp command in the UNIX shell.
Martin

Similar Messages

  • How to copy the java concurren program in oracle application

    Hi All
    I am working in oracle Apps R12.
    In AP (Account Analysis Report) is registered as java concurrent Program.
    Now i need to customize this concurrent program and add two new column and two parameter in that.
    Could any one pls provide me the steps that how to copy the Java concurrent,and make a new customized program.
    Whether copying a java concurrent program is same as cp registered as oracle report.
    Thanks & Regards
    Srikkanth

    Hi Sir,
    Thanks for your reply.
    I have find the xml file form data definition and in that they have written Sql query and they have called a Package.
    And the i have also taken the class file from the path as mentioned.
    Now i need to customize this report by adding two parameter and i need to add two new column to display in the rtf.
    Can you pls tell me the steps to copy or how to customize this report.
    Regards
    Srikkanth

  • How to execute external program in java?

    My question is how to execute an external program in java.
    I need to call a unix command in java.
    Thanks.

    it depends on what you are trying to do. Following are the two methods
    1. Runtime.exec() : this method allows you just to call an external program as a seperate process
    2. JNI (Native Interface) :- As of right now only C and C++ are supported by this method. This method allows you to directly call the C/C++ methods from JAVA

  • How to call external files from java?

    How to call external files in java. For example how to call a *.pdf file to open in its default editor(say Acrobat), or a *.html file to open in the default browser or a *.txt file in a notepad etc..,
    In my program i have *.chm (Compiled Windows HTML Help) help file. how to open it in its default editor it?

    Jayarathina_Madharasan wrote:
    no one answered my questionHi what wrong did i do...basically insulted all the volunteers here who took the time to consider your question and try to offer you help. Other than that, you did nothing wrong.
    From JavaRanch :
    And even if an answer doesn't solve your problem, even if it should totally miss the point - the best thing to do to motivate others to continue trying to help you is showing respect and gratitude for the investment of time that was put into dealing with your issue.
    Edited by: Encephalopathic on Apr 14, 2008 10:01 AM

  • External and Advanced Java program???

    Hi Experts,
      In what situation we come across to write an External and advanced Java program for lookups into target database tables, used adapter channel API. And later this program is used for lookups only when (condition) Interface quality of service (QoS) is Exactly Once
    Thnx
    Andy

    Sorry: what is the questione here?

  • How can I call external exe in java

    Hi ,
    Is It Possible to call external exe in java.
    I read Runtime.exe("some exe") but actually my exe expects some input to process for that how can i pass the input to my exe and how can get the response from exe to my java class.
    any sample code is welcome.
    Thanks
    Babu H

    example
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import java.io.*;
    public class RuntimeExample extends JFrame {
        private JTextArea textArea;
        private JTextField textField;
        private PrintWriter writer;
        public RuntimeExample()
            init();
            initProcess();
        public void init()
            textArea = new JTextArea(20, 80);
            textArea.setEditable(false);
            textField = new JTextField(30);
            textField.addKeyListener(new KeyAdapter()
                public void keyPressed(KeyEvent event) {
                    if (event.getKeyCode() == KeyEvent.VK_ENTER)
                        if (writer != null)
                            textArea.setText("");
                            writer.print(textField.getText() + "\r\n");
                            writer.flush();
                            textField.setText("");
            Container container = getContentPane();
            JScrollPane scrollPane = new JScrollPane();
            scrollPane.setViewportView(textArea);
            container.add(scrollPane, BorderLayout.CENTER);
            container.add(textField, BorderLayout.SOUTH);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            pack();
            textField.grabFocus();
            setVisible(true);
        public static void main(String[] args) {
            new RuntimeExample();
        public void initProcess()
            Runtime rt = Runtime.getRuntime();
            try
                //Process p = rt.exec(new String [] {"cmd", "/C", textField.getText()});
                //textArea.setText("");
                //textField.setText("");
                Process p = rt.exec("cmd");
                writer = new PrintWriter(p.getOutputStream());
                Thread thread1 = new Thread(new StreamReader(p.getErrorStream()));
                Thread thread2 = new Thread(new StreamReader(p.getInputStream()));
                thread1.start();
                thread2.start();
                System.out.println("Exit Value = " + p.waitFor());
            catch (Exception ex)
                textArea.append(ex.getMessage());
                ex.printStackTrace();
        public class StreamReader implements Runnable
            InputStream is;
            public StreamReader(InputStream is)
                this.is = is;
            public void run()
                try
                    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
                    String data;
                    while ((data = reader.readLine()) != null)
                        textArea.append(data + "\n");
                    reader.close();
                catch (IOException ioEx)
                    ioEx.printStackTrace();
    }you can pass input to the exe by using getOutputStream() from Process and get the output from getInputStream() from Process

  • 2 Instances in Configtool and offlinecfgeditor after System Copy ABAP+Java

    Hello,
    I've done a system copy ABAP+JAVA of a XI3.0 (WAS 6.40) and after the system copy I've my system up & running.
    The problem is:
    After I have finished the System Copy (Export and Import) of the ABAP and Java part I'm doing the pre-steps for the Upgrade to PI 7.1.
    Ok, following the note 1061649 on the point "Checking the Consistency Between Primary Application Server Instance ID and Box Number" when I check this point I'm in trouble because my Java ID (the same Java ID of the source system of the system copy) isn't the JAVA ID that the checks waits for my destination server.
    The result of the check is:
    java -cp instanceidcheck.jar com.sap.sdt.check.InstanceIdChecker ID84971 21 XIDDVEBMGS21sapxid
    The calculated instance ID is ID2190439
    WARNING!!! The source system ID that you provided (ID84971) is different than the one calculated (ID2190439)
    You will have problems installing the shadow system and running the migration.
    Then, I go to see in configtool my InstanceID and I see that I have 2 InstanceID's....the instanceID ID2190439 that is empty (no dispatcher and no server0) and the instanceID ID84971 that has dispatcher, server0 and is the instance which is starting when I type "startsap sapxid".
    Can you tell me why is happening that ??
    Regards,
    Albert

    Hello,
    I've done a system copy ABAP+JAVA of a XI3.0 (WAS 6.40) and after the system copy I've my system up & running.
    The problem is:
    After I have finished the System Copy (Export and Import) of the ABAP and Java part I'm doing the pre-steps for the Upgrade to PI 7.1.
    Ok, following the note 1061649 on the point "Checking the Consistency Between Primary Application Server Instance ID and Box Number" when I check this point I'm in trouble because my Java ID (the same Java ID of the source system of the system copy) isn't the JAVA ID that the checks waits for my destination server.
    The result of the check is:
    java -cp instanceidcheck.jar com.sap.sdt.check.InstanceIdChecker ID84971 21 XIDDVEBMGS21sapxid
    The calculated instance ID is ID2190439
    WARNING!!! The source system ID that you provided (ID84971) is different than the one calculated (ID2190439)
    You will have problems installing the shadow system and running the migration.
    Then, I go to see in configtool my InstanceID and I see that I have 2 InstanceID's....the instanceID ID2190439 that is empty (no dispatcher and no server0) and the instanceID ID84971 that has dispatcher, server0 and is the instance which is starting when I type "startsap sapxid".
    Can you tell me why is happening that ??
    Regards,
    Albert

  • Problem while spawning scp (secure copy) in Java

    Hi,
    We are calling shell script to spawn scp (secure copy) in Java. JVM version is 1.4.2. While trying to invoke this shell script on JVM 1.4.2 in UNIX environment, it doesnot give desired result. Either it gives the error as :
    1)
    "The authenticity of host 'sxfer01.bluecrossmn.com (159.136.224.30)' can't be established.
    RSA key fingerprint is 8d:84:82:c2:bb:15:94:e1:30:e1:11:0e:3f:8b:83:24.
    Are you sure you want to continue connecting (yes/no)?"
    After saying "yes", it hangs.
    OR
    2) It doesnot display the value for output variables. Value will be blank and it goes back to system prompt. It doesnot hang.
    So How to treat scp utility in JVM 1.4.2? Any change / configuration to be done ?
    Thanks,
    Asawari

    As a guess....
    1. You first need to understand how to run the command successfully from a command prompt.
    2. Again from the command prompt you then need to understand what sort of errors the command can generate and what action you need to take based on those errors.
    3. You need to create (ONLY after 1 and 2 are complete) a command line simulator which MUST use threads in java. Your simulator knows how to correctly accept all possible responses from the command and how to respond to them. (And you better understand how java shells out commands and handles streams for them as well.)

  • System copy : As Java : Non-unicode kernel Option not available

    Dear All,
    we are performing AS Java system copy to create a new system , same SID , same HOST and same Configuration except OS is upgraded.
    Susle Linux OS - 11 SP3
    As Java Nw 701
    kernel version -
    NW701 - Kernel 721_Ext - Non_unicode - 201 patch level
    We have successfully completed export and now we are importing the same export in new server,now while performing taget installation we are not getting option to install NON UNICODE kernel , except it is only asking for UC Kernel 7.20/7.21.
    Current version of system is non-unicode and we will like to keep it that way.
    May I know is non-unicode system copy option is not available? is it removed ?
    and if we want to install non-unicode then how we can perform that ?
    Can we install target system using UC kernel and later just perform NON-unicode kernel upgrade, will this work?
    Has anyone faced such concern?
    Guidance will be appreciated.
    Regards,
    Bond

    Thanks for  update RB.
    We have tried this method as in we stop SAP and sync file systems and perform DB/Backup restore method. This method works but unfortunately I am not able to find any SAP relevant document to support this method for so called "java" systems.
    SAP only suggest to perform system copy for "java" hence we are trying via export import. Currently I am looking into options of using old master installation software.
    although, can i request you if you any SAP relevant note or kba or any other in which SAP support/suggest we can perform file system copy and db restore for "Java" systems then it will be just a thing which I need to go ahead with method you suggested.
    Thanks , kindly update.
    Warm Regards,

  • Calling external programs from Java?

    Hi All,
    Is there a way of calling external applications from Java without using Runtime.exec(). That method seems quite messy when you are dealing with streaming data from an input file to an output file. Basically what I'm asking is there a way to run a command the same way you would type it in a command shell?
    Thanks

    LeWalrus wrote:
    Ok, I've an external application that I want to be called inside a Java GUI. It has several input arguements, which the format looks something like:
    programname inputfile > outputfile
    Simple enough.
    >
    Works fine from a shell command line. From what I understand, this won't work using Runtime.exec() because that method will just start the application. Works fine from Runtime.exec(). Since you are'>' to write stdout to a file you need to us a shell to execute the command.
    String[] command = {"sh", "-c","programname inputfile > outputfile"};
    Process process = runtime.exec(command);
    You need to read, digest and implement the recommendations given in http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html .
    File input and output from the application has to be taken care of programatically (java.io stuff). Fine if you've only one input and output. But if you have several input files and hundreds of output files, where does this leave you. It would be much easier if you could pass a string command to the shell directly as if you typed it in the command line yoursel!

  • Block copying in java

    Hey guys,
    I am working on a display module for one of my demos. The display module displays a speech signal. When I record data in realtime I need to shift the display buffer so that the old data is thrown and the new data is added. To shift an buffer, using a for loop looks very inefficient. Is there a "block copy" in java or is there a better way doing it..
    thanks,
    Theban

    I need to shift the display buffer so that the old data is thrown
    and the new data is added.The really real way to do this is to use a circular buffer. Assuming the other parts of the program aren't impacted negatively.

  • Including External JARs for Java Application in OC4J

    Hi Experts,
    Here is my requirement.
    I have developed my Java application using Tomcat Server & Eclipse. In my application I have used some External JARs & imported the classes in my JSP.
    Now that I'm using OC4J Server instead of Tomcat I'v no clue as to where I have copy these External JARs for my application to work.
    I have installed OBIEE-Client which includes OC4J server. The path where I have placed my application is as below
    *"C:\OracleBI\oc4j_bi\j2ee\home\default-web-app"*
    If I run my application the server does not import the classes in the JSP which we include using Import statement using JSP tags (*ex* - <%@ page import = "org.apache.commons.fileupload.*"%>).
    This is the location which I found, where I need to put my Java-J2EE application. This OC4J_BI comes with OBIEE.
    Kindly help me out on where to place these External JARs exact location in OC4J.
    Also let me know if I have to alter any configuration/xml file (if so pls specify the file name & its location).
    Thanks in advance,
    Venky

    You can either include the external libraries in the application, by placing them into WEB-INF/lib, or you can import them into the server as "shared libraries", normally you'd use the "enterprise manager" application to do this. Having loaded a shared library you then add it to the classpath when you're deploying the application.

  • S.O.S PROBLEMS COMUNICANTING EXTERNAL PROCESSES IN JAVA UNDER LINUX

    I've programmed a little program in C called "cinterpreter" which works like
    an interpreter, when it launches it shows a welcome message to the display
    (standart output), then is always waiting for strings from the keyboard
    showing the length of the input strings until the "quit" string is received,
    in that case the C program named "cinterpreter" finish, here we can see the
    code:
    # include <stdio.h>
    # include <string.h>
    # include <stdlib.h>
    char presentacion[8][80] = {
    " ||||||||||||||||||\n",
    " --- Welcome to Maude ---\n",
    " ||||||||||||||||||\n",
    " Maude version 1.0.5 built: Apr 5 2000 15:56:52\n",
    " Copyright 1997-2000 SRI International\n",
    " Thu Aug 9 13:40:25 2001\n",
    " \n",
    " \n"};
    void longitud(char * cadena)
    int t;
    for(t=0;t<3;t++)
    printf("MAUDE_OUT> la cadena %s tiene %d caracteres\n",cadena,strlen(cadena));
    fflush(stdout);
    int main()
    char cadena[80];
    int i;
    char ch;
    for(i=0;i<8;++i) printf("%s",presentacion);
    printf("\n");
    fflush(stdout);
    do {
    printf("Press any key to continue\n");
    scanf("%c",&ch);
    printf("%c\n",ch);
    fflush(stdout);
    }while (ch != 'q');
    printf("\n");
    while( strcmp(cadena,"quit") !=0)
    printf("\nMAUDEENTRADA>");
    fflush(stdout);
    scanf("%s",cadena);
    longitud(cadena);
    I'm intereted in running this program, control it's standart input and
    starndart output through a java program through the Runtime , process class
    and the correponding methods like "exec", getInputStream, getOutputStream,
    getErrorStream, the question is that I do not Know what I'm doing wrongly but
    I don't get what I want, I'm interested in sending input to the C subprocess
    thorugh its stdin getting it by getoutputStream method, and then read its
    answer from its stdout getting it by getoutputStream, then question is that I
    can sent de first string and read the first answer but I can't repeat it
    again, and I would like to begin a dialog with the subprocess so I need to
    send many messages and receive its answer to it, but many times, not just one,
    by the moment I got it but just one, if any body can help with this please
    answer the question or send any answer to the next adresses
    e-mail:
    [email protected]
    [email protected]
    *************** java code **********************
    import java.io.*;
    public class mioss {
    static String proceso = "/bin/cinterprete";
    static Process p = null;
    //--------- input writting method -----------
    static void escribe(OutputStream procesoescribe, String s) {
    BufferedWriter laentrada = new BufferedWriter(new
    OutputStreamWriter(procesoescribe));
    try{
    laentrada.write(s + "\n");
    laentrada.flush();
    }catch(IOException e) {System.out.println("error de escritura");}
    //----------- output reading method ---------------
    static void leesalida(InputStream procesosalida){
    String l;
    BufferedReader lasalida = new BufferedReader(new
    InputStreamReader(procesosalida));
    try{
    while ((l = lasalida.readLine()) != null){
    System.out.println(l);
    } catch(IOException e) {System.out.println("error de readline");}
    //------------- reading error method --------------------
    static void leerror(Process p){
    String l;
    BufferedReader elerror = new BufferedReader(new
    InputStreamReader(p.getErrorStream()));
    try{
    while ((l = elerror.readLine()) != null){
    System.out.println(l);
    elerror.close();
    } catch(IOException e) {System.out.println("error de readline");}
    //--------------- principal method main -------------------------
    static Process proc = null;
    public static void main(String [] Args) {
    try{
    Runtime r = Runtime.getRuntime();
    proc = r.exec(proceso);
    escribe(proc.getOutputStream(),"map(+2)[3,3]");
    leesalida(proc.getInputStream());
    escribe (proc.getOutputStream(),"map(*3)[2,2]");
    leesalida(proc.getInputStream());
    }catch(Exception e) {System.out.println("error de ejecucion del
    proceso");}
    System.out.println("THE END OF THE PROGRAM");

    The problem is with the leesalida method.
    There you are reading form the output sream of the process usingBufferedReader.readLine.
    readLine returns null only when it gets to the end of the stream, or here the stream ends only when the external processes ends.
    You can modify your code like this:
    public class mioss {
        static String proceso = "cinterprete";
        static Process p = null;
        //--------- input writting method -----------
        static void escribe(OutputStream procesoescribe, String s) {
         BufferedWriter laentrada = new BufferedWriter(new
             OutputStreamWriter(procesoescribe));
         try{
             laentrada.write(s + "\n");
             laentrada.flush();
         }catch(IOException e) {System.out.println("error de escritura:" + e);}
        //----------- output reading method ---------------
        static void leesalida(InputStream procesosalida, int nLines){
         String l;
         BufferedReader lasalida = new BufferedReader(new
             InputStreamReader(procesosalida));
         try{
             while(nLines-- > 0) {
              l = lasalida.readLine();
                    System.out.println("from java:\t" + l);
         } catch(IOException e) {System.out.println("error de readline");}
        //------------- reading error method --------------------
        static void leerror(Process p){
         String l;
         BufferedReader elerror = new BufferedReader(new
             InputStreamReader(p.getErrorStream()));
         try{
             while ((l = elerror.readLine()) != null){
                    System.out.println(l);
             elerror.close();
         } catch(IOException e) {System.out.println("error de readline");}
        //--------------- principal method main -------------------------
        static Process proc = null;
        public static void main(String [] Args) {
         try{
             Runtime r = Runtime.getRuntime();
             proc = r.exec(proceso);
             leesalida(proc.getInputStream(), 9);
             escribe(proc.getOutputStream(),"first");
             leesalida(proc.getInputStream(), 4);
             System.out.println("Done first !\n");
             escribe (proc.getOutputStream(),"second");
             leesalida(proc.getInputStream(), 4);
             System.out.println("Done second !\n");
         }catch(Exception e) {System.out.println("error de ejecucion del proceso");}
         System.out.println("THE END OF THE PROGRAM");
    } Regards,
    Iulian

  • PI 7.1 system copy (abap+java)

    Hello,
    We need homogenous copy of PI 7.1 system to an existing system (newly installed PI 7.1). I would like to use database specific option (oracle).I was studying SAP guide for System copy of PI 7.1 and there are slight diff comparing to NW 7.0 double stacks.
    Comparing to NW 7.0 double stacks I can't see here step for exporting central instance where application specific filesystem and SDM filesystem was archived (I know SDM is not present  in 7.1 anymore). In addition I can see in guide for 7.1 new option for database refresh. However this section also does not describes any needs for taking special care of java filesystem content.Does it mean that I do not need to take special care for java filesytem content anymore on 7.1?
    I am bit wondering if it is sufficient for 7.1 just to refresh DB (with restore method for oracle for example) and then perform just adaptation of java IDs in profiles as described in section for database refresh of system copy guide PI 7.1? Will be this way system consistent (consistent abap part and consistent java part)? On NW 7.0 after restore of DB only, java part would be not consistent, is this new in 7.1?
    Thanks for your feedback in advance

    Hello -
        Since you need the complete ABAP and JAVA databases, you will want to use the system copy tool on the installation CD. If you are using a Micrsoft SQL system, you will be able to save yourself some steps. Here is what we did for our MSSQL refresh:
    Use sapinst to do a file system export on the source system.
    Take back up of source system and use sapinst to restore it to target system.
    Process
    1. Detach the database files from the source system database or create a backup and copy the files
    to the target system.
    2. Attach the database files or restore the backup of the source database on the target database server.
    3. Run SAPinst to install the target system by choosing the following on the Welcome screen:
    <Your SAP system> Software Life-Cycle Options System Copy Target System <system variant>
    <technical stack> .
    Let me know if you have more questions or if you need more information. I can try and answer a few if you are trying to use ORACLE and UNIX / LINUX. Thanks! - Will S.

  • Problem in connecting external URLs from Java ME Platform SDK 3.0

    Hello all,
    I am building a mobile application using Java ME Platform SDK 3.0. My application needs to connect to external web services. I have finished development of first module and it is running perfectly from actual mobile device. But the problem is:
    While developing the application I am used to test it with given mobile Emulators in Java ME Platform SDK 3.0. During this test I am not able to connect to external web service if I am testing if within local intranet using proxy server. To solve this I have configured Proxy Setting in the IDE at:
    Tools Menu -> Options -> General -> Manual Proxy Settings and given HTTP Proxy Server and it's Port. The same proxy settings are there in all web browsers in my machine.
    But It is giving error like:
    Unknown error 10054 during socket::read
    Strange thing is that the same application is running perfectly If my PC is not in Intranet and connected to internet directly.
    Please help me that how can I set proxy settings in Java ME Platform SDK 3.0 to get in working?
    Any suggestions regarding this will be helpful for me.
    Thanks to spare some time and read my post,
    Tejas.

    Hi Tejas,
    it should work. I tested it right now and my proxy was used without any problems. The way how you set proxy settings is correct.
    Could you try following to verify that it is a proxy problem or not, please?
    1. run demo application "Demos" (from Start Page or File->Open Sample Project)
    2. choose "HttpView" midlet and start it
    3. choose "cnn"
    4. if proxy is set correctly, you will see page source; otherwise you will get an error message
    If the demo runs fine, the problem is probably somewhere else in the communication.
    There is one limitation in proxy settings. Only proxy without username and password is supported. Isn't it your case?
    Regards,
    Radko

Maybe you are looking for

  • Share iCloud drive with family members

    Has anybody figured out how to share iCloud drive with family members? I was using Amazon Cloud drive which used to have an app you could download and imbed into Finder, but with OS X 10.1 this is no longer supported so I've switched over to iCloud d

  • Acrobat Pro XI won't update using CC desktop

    I have CC for teams and Acrobat XI Pro will not update through the Creative Cloud desktop app on Macs (haven't tested Windows yet). As a test I removed all instances of Adobe from my system (apps, application support files, prefs, launch daemons, eve

  • Expanding the appearance of live transform breaks up fill and stroke

    Okay, so I never ever use Effect > Distort & Transform > Transform, but with all the hubbub about the stroke scaling bugs in Illustrator CC 2014, I've been fiddling with it lately, and I'm confounded by something: once you perform a "live" transforma

  • Clear settings on 7911

    How do I clear all settings to include network settings on a 7911? What information can't be cleared with this process? We are trying to use a phone for a sensitive and non-sensitive network. We need to be able to clear the phone before switching and

  • PDF/Research Document Organiser?

    Heya folks, this one goes out to those of you who are researchers/students/generally organised. I am looking for a good, Apple-ish (I.e. like iTunes, Aperture etc.) program for organising research documents that i download from the net. I would ideal