Use of Execute command tool

Post Reply
fx.brault
Newbie
Posts: 10
Joined: Thu Feb 27, 2014 8:28 am
Location: Roanne

Use of Execute command tool

Post by fx.brault »

Hi,

Sorry for my English, I'll try to be understandable.



I try to use the tool "Execute command" in order to edit text in xml file.

I must substitute "&" with "&amp" (Sometimes I have this character in a comment field and the XML Pickup tool does not recognize the structure of the xml)



Settings of Execute command (in french sorry) :



Commande ou chemin d'accès : /Application/Utilities/Terminal.app

Arguments : sed "s/&/&amp/g" %1 >> %2

Sortie : Fichier au chemin d'accès

Copier travail d'entrée : Oui

Extension de sortie : XML (*.xml)



when I made ​​this command on a local file, it works fine, but it does not work with Switch.

I'm not sure of my use of %1 and %2.

The resulting file must have exactly the same name as the input file.



If someone has already encountered this problem or if someone explain to me some different settings on this tool.

Thank you for your help



FX
dkelly
TOP CONTRIBUTOR
Posts: 658
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Use of Execute command tool

Post by dkelly »

You can call "sed" directly and not call Terminal.app. Your problem will be correctly escaping the & characters.
fx.brault
Newbie
Posts: 10
Joined: Thu Feb 27, 2014 8:28 am
Location: Roanne

Use of Execute command tool

Post by fx.brault »

Thank you for your reply.

I called "sed" directly and changed Argument

New setting :

Command : sed

Argument : "s/&/&amp/g" %1 >> %2

Sortie : File at path



Nothing happens. I tried to change the settings of output but the only result obtained was creating an empty folder ...

I think there's a concern in the argument. Is the% 1 and% 2 are sufficient for the output file has the same name? When I do the command in a terminal I must state the name of the output file.

Thank you for your help.



FX
jonasy
Member
Posts: 30
Joined: Tue Feb 01, 2011 11:50 am

Use of Execute command tool

Post by jonasy »

I believe that redirection is a feature of the bash shell which is used in Terminal. Switch doesn't use bash, instead it sends the command directly to the operating system which is why features from bash are not available.



You can work around this using a bash script which obviously has the features of the bash shell. You can send the input and output paths to the shell script via arguments.



The bash script will look like this:



#!/bin/bash

sed "s/&/&amp/g" "${1}" >> "${2}"



And the Execute command will be configured like this:

Command or path: /path/to/bash/script.sh

Arguments: "%1" "%2"

Output: File at path
fx.brault
Newbie
Posts: 10
Joined: Thu Feb 27, 2014 8:28 am
Location: Roanne

Use of Execute command tool

Post by fx.brault »

Thank you, it works perfectly.



Just a question for the next time. The variable ${1} and ${2} are substituted by %1 and %2. Is it the order of appearance in the argument that causes this or that is the number 1 and 2 in the variables?



Thank



FX
jonasy
Member
Posts: 30
Joined: Tue Feb 01, 2011 11:50 am

Use of Execute command tool

Post by jonasy »

It's the order of appearance.



Switch executes this:

/path/to/script.sh "/path/to/input.xml" "/path/to/output.xml"



So the bash script receives the paths itself and uses them as first and second variable in itself.
fx.brault
Newbie
Posts: 10
Joined: Thu Feb 27, 2014 8:28 am
Location: Roanne

Use of Execute command tool

Post by fx.brault »

OK, thank you for that clarification.
jbveenstra
Newbie
Posts: 1
Joined: Thu Jan 21, 2016 10:44 am

Re: Use of Execute command tool

Post by jbveenstra »

@jonasy

Great explanation, thnx
I was wondering though, how can I see the code Switch is actually executing?
At this moment I'm trying some more complex script where the bash script converts a file to another filetype
Your example worked, but this one doesn't
Below the settings of the Execute command

Command or path
/path/to/script/test.sh
Arguments
Single-line text with variables defined
"%1 [Job.NameProper].xls" "%2 [Job.NameProper].csv"
Output
File at path
Output extension
Automatic

test.sh
#!/bin/bash
in2csv "${1}" | csvformat -T > "${2}"
Post Reply