Skip to main content
Content Starts Here Search Solutions

Solution Detail

 
Solution TitleI can't get this command-line application to work in the Execute Command Tool. How can I fix this?
Solution Number00000398
Solution Details
Symptoms
I have configured the Execute Command Tool to work with a command line application, however I receive wrong output, no output, or the job is moved to the 'Problem Jobs' folder.

Background
The easiest way to create a working configuration for the Execute Command Tool is by first create a working command in Command Prompt on Windows or Terminal on Mac. Then you can configure the Execute Command based on the command from which you know gives the expected result. 

When you have a working command in Command Prompt or Terminal you will need to translate it to a configuration of the Execute Command Tool in Switch. There are two kinds of changes which need to be done on the working command:

  • Keep in mind the command and the behavior of the command-line application and which settings of the Execute Command Tool reflect that behavior.
    Please check the documentation to know the exact behavior of each setting of the Execute Command Tool.
  • Keep in mind that Switch will execute the command directly in the operating system while Command Prompt and Terminal uses a shell. This results in some differences in behavior, the most important one being that you always have to provide the full path to the command-line application in Switch, even when this is not necessary in Command Prompt or Terminal.


Solution

1 The most common issues.

The most common mistake when trying to configure the Execute Command Tool is that the user provided the name of the command instead of the full path to the command in the ‘Command or path’ property. The only exception where it is not necessary to provide the path to the command-line application is when using commands from the operating system itself.

Sometimes, it is not that obvious to know the location where a command-line application is installed because you don’t need this information to be able to use the application in Command Prompt or Terminal. In this scenario, you can search for the location in the documentation of the application or search for the application on your disk.

On MacOS X, you can use Spotlight to search for the application. Please note, that it will be necessary to configure Spotlight to search in system files; you can find out how on the following page:

http://support.apple.com/kb/HT4355

On Windows, you should be able to find the application in one of these folders:
C:\Program Files\
C:\Program Files (x86)\

The second most common mistake is forgetting to add quotes around the placeholders (%1, %2, %3). Usually Switch will replace the %1, %2, %3 placeholders with paths located in the Switch Application Data Root. This can cause an issue when not placing the placeholders in quotes, because the default location of the Switch Application Data Root has a path which contains a space. 

When you build a command with an argument (for example, a path) which has a space in it, then it is necessary to place the argument in quotes to show that the complete path is one piece, not two arguments separated by a space.

2 More complex issues

When you have a complex issue when configuring the Execute Command Tool, it is advised to enable debug logging. You can enable debug logging using these steps:

Switch 11 and earlier:

  • Open the Switch preferences on the logging category
  • Set “Log Debug Messages” to 'Yes'
  • You can see the debug messages in the messages pane
Switch 12 and later:
  • Open the Switch preferences on the logging category
  • Set “Log to Text File” to 'Yes'
  • Set “Log Debug Messages” to 'Yes'
  • You can find the debug messages in the text logs on the following location:
    /Users/<username>/Library/Application Support/Enfocus/Switch Server/logs/
    C:\Users\<username>\AppData\Roaming\Enfocus\Switch Server\logs\
    (These locations can be different if you changed the location of the Switch Application Data Root)

When the Execute Command Tool executed a command you will see the following debug messages:

Executing
This contains the complete command which Switch will execute after it replaced the placeholders with the actual paths.

Outcode
The outcode/exitcode of the command. Switch decides whether or not the command was successful.

Stdout
This is the output of the command in case everything went OK. This is the same output as you would see when executing in Command Prompt or Terminal.

Stderr
This is the output of the command in case everything went wrong. This is the same output as you would see when executing in Command Prompt or Terminal. So, if something went wrong, then most likely this will contain useful information on what went wrong.

Usually, you can figure out what is wrong when looking at the command Switch executed and the Stderr output. If there is no output in any of the above, then the operating system failed to execute the command itself. Check if the path to the executable is OK and if you have sufficient permissions.

3 Redirecting 

Redirecting output from a command to a text file is a feature of the shells used in Command Prompt and Terminal; therefore, it is not directly possible using the Execute Command Tool in Switch. You can work around this by creating a batch file which uses a shell supporting redirecting. Then you can use the batch file as command and send input and output paths as arguments to the batch file. 

An example configuration for Mac could be:

Setup of the Execute Command Element:
Command or path: /path/to/bash/script.sh
Arguments: "%1" "%2"
Output: File at path

Contents of the script.sh batch file:
#!/bin/bash
sed "s/\&/\&amp;/g" "${1}" >> "${2}"
(This example will replace “&” by “&amp;” in text files)

 
Does this solution help you answer your question?