• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 287
  • Last Modified:

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
0
tjgquicken
Asked:
tjgquicken
  • 3
  • 2
1 Solution
 
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
 
CEHJCommented:
Try also

Runtime.getRuntime().exec(new String[] {"ditto", "-c", "-k", "--keepParent", "-rsrc", srcFile, destFile}).
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now