Java and Darwin

I have a Java applet that runs on Mac OS X and the underlying Darwin interface. The applet makes the following system call:
Runtime.getRuntime().exec("ditto -c -k --keepParent -rsrc " + srcFile + " " + destFile).

This system call works fine if there are no spaces in srcFile, but (of course) it doesn't work if there's a space. My problem is that when I put quotes around srcFile, like
Runtime.getRuntime().exec("ditto -c -k --keepParent -rsrc \"" + srcFile + "\" " + destFile)    or Runtime.getRuntime().exec("ditto -c -k --keepParent -rsrc '" + srcFile + "' " + destFile)
that doesn't work either. The ditto command creates destFile, but it's empty.

The problem isn't with the ditto command, because I can use Terminal and type
ditto -c -k --keepParent -rsrc "/Users/computer/Desktop/test file.qdfm" /tmp/file1.tmp   or
ditto -c -k --keepParent -rsrc '/Users/computer/Desktop/test file.qdfm' /tmp/file1.tmp
and both work as expected. Does anybody know what I'm doing wrong?

Thanks,
Jay
tjgquickenAsked:
Who is Participating?
 
CEHJConnect With a Mentor Commented:
Try also

Runtime.getRuntime().exec(new String[] {"ditto", "-c", "-k", "--keepParent", "-rsrc", srcFile, destFile}).
0
 
CEHJCommented:
Does it work when there are *no* spaces?
0
 
ellandrdCommented:
taken from:

http://www.experts-exchange.com/Programming/Languages/Java/Q_22743766.html

OK here is what im testing and it works for me:

/*
 * Main.java
 *
 * Created on 06 August 2007, 13:19
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package javaapplication1;

/**
 *
 * @author sdelaney
 */
public class Main {
   
    /** Creates a new instance of Main */
    public Main() {
    }
   
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
            String filename ="W:/Java/JavaApplication1/raymond questions.txt";
            Runtime rt = Runtime.getRuntime();
            final Process proc = rt.exec(
                new String[] {
                "cmd.exe",
                "/c",
                "\"\""+filename+"\"\""
            }
);
        } catch(Throwable cause) {
        }
    }
}
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
tjgquickenAuthor Commented:
Yes, it works correctly when there are no spaces. I'm going to try the exec command with the String array parameter and report back.
0
 
tjgquickenAuthor Commented:
The overloaded exec command worked. Thanks.
0
 
CEHJCommented:
:-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.