Free Trial

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Run a batch file from Run Command tool

StephenMack
10 - Fireball

Ok, so because the email tool doesn't include authentication I've been forced to write my own email workaround

 

- I have a workflow that spits out a report in HTML

- I wrote an EXE that takes in the HTML (with inline images) and processes it to be the body of the email, and finally sends the message

 

It looks like the run command can't accept an input string as a command for example:

SMTP_Command.exe "From@email.com" "To@email.com" "subject"

 

So I have my workflow outputting the appropriate string to a batch file and I'm trying to open that.

 

But now I'm even confused as to how I can run this batch file. I absolutely can't wrap my head around Write source, read source, etc. I just want to write this string to a command line and be done with it. No matter what I try I get some type of error that and input or output needs to be configured.

 

Thanks everyone!

 

Side note: alteryx please fix the email tool, this is a ridiculous amount of side work to be doing just because you didn't include SMTP authentication.

16 REPLIES 16
david_fetters
11 - Bolide

Authentication is something we'd all like to see!  add your two cents to these posts: https://community.alteryx.com/t5/Alteryx-Product-Ideas/Authenticate-Tool-SMTP-Address/idi-p/1740

https://community.alteryx.com/t5/Alteryx-Product-Ideas/Authentication-input-options-for-Email-Tool/i...

 

As far as just running a basic batch file from the command tool, this works:

 

Capture.PNG

 

This was just a simple batch file: ECHO Hello; PAUSE;

 

You can pass arguments into it by using the command arguments option.  I have a few of these inside batch macros so that I can pass the arguments in as control inputs.

 

The Write Source option allows you to take the data stream coming into the Run Command and write it to a file (so that whatever you end up running can use this data and you can ensure that it exists prior to running the command).  This is a required option if you have data coming into the Run Command.

 

Read Results is for the opposite case, where whatever command you are executing create some sort of results file.  You use the Read Results option to grab this results file and bring it back into the data stream for down stream processing.  Read results is required if your run command output is connected to a downstream tool.  Hope this helps!

 

 

StephenMack
10 - Fireball

So this is the batch file I'm trying to execute. Since it's sending an email I don't need to read in anything else, this is the end of the line. 

 

The problem is my arguments are email sender, email receiver, and subject. From what I can tell I can't use variables to define the arguments in the run command tool. So I have a formula create the string I want to run in the command prompt and outputs it to a .bat file. Now all I have to do is open that batch file and I'm done.

 

I still get an error "Either an Output connection or Input connection is required.

 

run command setup.PNG

AdamR_AYX
Alteryx Alumni (Retired)

Here is a basic batch script example workflow

Adam Riley
https://www.linkedin.com/in/adriley/
david_fetters
11 - Bolide

To get rid of that error, hook the input of your Run Command to the end of your data stream, then set the Write Source to %temp%\temp.yxdb (basically just to satisfy the requirement that it is hooked to something, we'll output a file to the temporary file location).

 

Or use AdamR's method above (which is very elegant!) to create the batch file in stream, write it to the disk in Alteryx temporary storage, and then execute it.

AdamR_AYX
Alteryx Alumni (Retired)

I've decided that having used this technique three times in the Solution Center at the Inspire conference this year it is time for a CReW macro to run batch files.

 

Coming soon...

Adam Riley
https://www.linkedin.com/in/adriley/
StephenMack
10 - Fireball

Thanks for the demo workflow. I get output when I run yours, but I'm trying to get it to work with my file paths but I get 

 

"....sendMail.bat" returned an error code:1

 

run command setup.PNG

StephenMack
10 - Fireball

When I copy and paste the string that's going into the batch file it works from the command line. So it's not my syntax there

AdamR_AYX
Alteryx Alumni (Retired)

Your command must not be returning 0.

 

Just add

 

exit 0

 

at the end of the batch file to force a 0 return

Adam Riley
https://www.linkedin.com/in/adriley/
StephenMack
10 - Fireball

Still get the error when I add exit 0 to the end.

 

When I run the bat file from the command line it works perfectly (both ways, with exit 0 and without).

 

Oddly, it saves the file just fine (when I click the link it runs and I get my email)

 

run command error.PNG

Labels
Top Solution Authors