Page 1 of 1

Use of Execute command tool

Posted: Mon Aug 25, 2014 6:34 pm
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

Use of Execute command tool

Posted: Mon Aug 25, 2014 7:57 pm
by dkelly
You can call "sed" directly and not call Terminal.app. Your problem will be correctly escaping the & characters.

Use of Execute command tool

Posted: Tue Aug 26, 2014 5:40 pm
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

Use of Execute command tool

Posted: Wed Aug 27, 2014 1:23 pm
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

Use of Execute command tool

Posted: Wed Aug 27, 2014 4:29 pm
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

Use of Execute command tool

Posted: Wed Aug 27, 2014 5:29 pm
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.

Use of Execute command tool

Posted: Wed Aug 27, 2014 5:40 pm
by fx.brault
OK, thank you for that clarification.

Re: Use of Execute command tool

Posted: Thu Jan 21, 2016 11:03 am
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}"