Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Knowledge Base

Definitive answers from Designer Desktop experts.

The Run Command: Write Source & Read Results

AlexKo
Alteryx Alumni (Retired)
Created

RunCommand.pngThe Run Command tool is a great way to take your workflow to the next level of efficiency. It allows you to interact with the command line directly, just as you would if you were to access it manually and type in a command. Which is great because sometimes we have a lot of important things to do in the command line.

Capture.PNG

Exhibit A

This post will discuss two features of the Run Command tool: the Read Results and Write Source configuration options. You'll note that they both say "optional", but the Run Commandexpects one or the other to be configured (or both) and will error if they are blank. These options both deal with files that are either used in the command (Write Source), orcreated by the command(Read Results).

Read Results


Let's start with that second case - you have a command line command being carried out in the Run Command, and you want tospit out the results to yourworkflow. The Read Resultsoption allows you to grab the output of your command and bring it into your Alteryx workflow.

If you stream anything out of the Run Command, you mustconfigure the Read Results.You may wonder why you need a file to stream in the result from your command - Just remember this is all happening outside of Alteryx,so if you want to bring something back into Alteryx you need to treat it as a data source.

You can configure this like an Input Data tool, by clicking “Input…”.

Capture.PNG

The example here was taken right from our documentation on the tool, and shows how we can create a temporary file in the command, navigate to it in the Read Results, and have that pass into the workflow after the Run Command tool.

N.B.%temp% is a placeholder for your Designer's temporary path, usually something like C:\ProgramData\Alteryx\Engine\blahblahblah. See this article for more information on Workflow Constants.

Write Source


This option would allow you to take some information from your workflow and incorporate it as a source in your command, sort of like how Neo suits up in the Matrix.

Capture.PNG

Actually, it's exactly like that.

The example I included on this articleuses a field in Alteryx with the entire command, and then writes that to a temporary .bat file. The Run Command then simply reads the batch fileand executes the command. I also included a Read Results here so we can see the output in the workflow, but it isn’t necessary.

Just like before,if you stream anything into the Run Command, even if you don't use it in the command itself, you must also have the Write Source configured.

write source.PNG

Troubleshooting Tips

1. Errors:

Sometimes you may get a weird error from the Run Command that is actually just being passed along from the command line. Most of the time these will tell you where they're from, and they will almost always just be pointing at something wrong in your Command Arguments.

error.PNG

These will usually have a error code associated with them as well - these are actually Windows error codes, so you may be able to find some more information by Googling around.

2. Input Schema:

Depending on the data you're bringing in, you may need to play with your Input Tool configuration to account for header rows, or wonky metadata. To get around these sort of things, try to treat your data as non-delimitted by configuring your Input as below:

input config.png

We’ll just have to make sure that our delimiter is set to \0 and that we don’t have the First Row Contains Field Namesoption checked.The "\0" is just a shortcut to tell Alteryx to use no delimiter when parsing fields – so all the text will come in natively separated only into rows. The “long way” is brought up in the Resolve File Typewindow that will pop up if you use a file type that is not in the drop down menu of the Input Tool configuration.

Thanks for reading!

Example workflow compiled in Alteryx Designer 10.6.

Attachments
Comments
eblee
6 - Meteoroid

Hello,

 

I am trying to run a VBScript using the run command, but I get an error standing that it failed as it is not a valid Win32 application. Is there a workaround for this or does this specific tool only support .bat and .exe files?

 

Thank you!

Liz

 

JohnJPS
15 - Aurora

Hi Liz -- can you try "CScript <scriptFilename>" as the command you're running?

eblee
6 - Meteoroid

Hi John, just tried your suggestion but got a different error stating "the system cannot find the file specified".

JohnJPS
15 - Aurora

I'm not sure if that means it can't find CScript or if CScript can't find the file.... could you try adding the full path to your scrip filename?

eblee
6 - Meteoroid

Actually we created a .bat file that ran the VBScript and that worked! Thank you either way! 

StephenR
Alteryx
Alteryx

I'm not sure if this is due to an update or what, but I couldn't find the file using %temp%/filename with my Python code.  I ended up having to walk through the engine directory to find the file and bring it into the script.  Here's what ended up working:

 

 rootdir = r'C:\ProgramData\Alteryx\Engine'

    for root, dirs, files in os.walk(rootdir):
        for file in files:
            if file == 'MYFILENAME': # use your filename here without file type extension
                filepath = os.path.join(root, file) 
                print filepath

Just thought I'd throw that out there if anyone else had that issue.

AshishBhavnani
8 - Asteroid

Hello @AlexKo and Fellow Community Users,

 

I am developing a workflow that uses the Run Command Tool to execute a Batch program. I have been testing the execution of the Batch program directly on Windows Command Line where it is throwing an error. 

 

However, when I run the workflow that uses the Run Command Tool to execute this batch program, it keeps on running without throwing an error. Can somebody provide few ideas on how to make the workflow stop and capture the error that this batch program is throwing in a log file.

 

As of now, I could not find a configuration for Run Command Tool that could enable me to capture the error message.

 

Regards,

Ashish 

simpucca
6 - Meteoroid

My run command tool workflow works as a normal workflow with %temp%\statfin-Dynamic_Query.bat but when I turn it into a macro, it cannot find the bat file anymore.

 

Anyone got run command tool working within a macro?

 

Write source path: %temp%\statfin-Dynamic_Query.bat

 

Run External Program Command:

%temp%\statfin-Dynamic_Query.bat

 

Working directory:

%Engine.TempFilePath%

 

Read results:

%temp%\statfin-Dynamic_Query.csv

 

I think I tried all possible %path% combinations and cannot understand why it does not work. When I navigate to temp file and run the .bat it generates a csv out of jsonstat file.

 

 

davidhenington
10 - Fireball

This saved me! Thanks! 

thedr9wningman
8 - Asteroid

Would this be the way I could write-out all the metadata that would normally be in an email to a temporary location and then send the email of the output logs separately?

I have a situation where I have an extract workflow, another workflow that checks status, and then depending on that status, enacts a runner of a 'write-out' workflow. Using email events results in, at minimum, 2 emails and I would like to find a way to combine the results of the extracts and the results of the write-out into one email. 

 

Since the workflows tend to know nothing about the number of errors until they're written (how WOULD they be so self aware? They're not Zen Masters!), I currently don't know how to inform stakeholders with one email. But I feel that would be ideal.