Sly_Boots
Sly_Boots

Reputation: 195

Terminal command works, but not when I run it in Ant

I can run the following terminal command just fine:

security cms -D -i ../MyMobileProvision.mobileprovision > provision.plist

However, when I run it in Ant, from an ant script in the exact same directory, terminal claims the provisioning file doesn't exist and it creates an empty file for provision.plist, which screws up the next step in my process. The ant code looks like this:

        <exec executable="security">
            <arg line="cms -D -i ../MyMobileProvision.mobileprovision > provision.plist" />
        </exec>

Am I missing something about how ant works? I'm no expert at build scripts but I can use ../ syntax to import properties files just fine, so I'm confused why a relative path isn't working for a terminal command that otherwise would work fine with it.

Upvotes: 0

Views: 200

Answers (1)

Chad Nouis
Chad Nouis

Reputation: 7051

In your terminal command example, the snippet...

> provision.plist

...is interpreted by your shell as a redirect command.

The <exec> task of Ant doesn't use a shell to execute commands. Instead, the > provision.plist is passed unmodified to the security program.

To get what you want, use the output attribute of <exec>. output is the name of a file where <exec> will write the output:

<exec executable="security" output="provision.plist">
    <arg value="cms" />
    <arg value="-D" />
    <arg value="-i" />
    <arg value="../MyMobileProvision.mobileprovision" />
</exec>

In the above example, I've replaced the <arg line="..."> with several <arg value="..."> elements. The reasoning from the Ant documentation on Command-line Arguments:

It is highly recommended to avoid the line version when possible. Ant will try to split the command line in a way similar to what a (Unix) shell would do, but may create something that is very different from what you expect under some circumstances.

Upvotes: 1

Related Questions