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 "&" (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/&/&/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
-
- TOP CONTRIBUTOR
- Posts: 628
- Joined: Mon Nov 29, 2010 8:45 pm
- Location: Alpharetta GA USA
- Contact:
Use of Execute command tool
You can call "sed" directly and not call Terminal.app. Your problem will be correctly escaping the & characters.
Use of Execute command tool
Thank you for your reply.
I called "sed" directly and changed Argument
New setting :
Command : sed
Argument : "s/&/&/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
I called "sed" directly and changed Argument
New setting :
Command : sed
Argument : "s/&/&/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
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/&/&/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
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/&/&/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
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
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
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.
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
OK, thank you for that clarification.
-
- Newbie
- Posts: 1
- Joined: Thu Jan 21, 2016 10:44 am
Re: Use of Execute command tool
@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}"
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}"