Alteryx Designer Discussions

Find answers, ask questions, and share expertise about Alteryx Designer.
Don't forget to submit your entry for the Excellence Awards by October 30! | Need more information about the program? Check out the blog here
SOLVED

Run Command Working Directory Issues

Highlighted
10 - Fireball

Hi,

 

I've been trying to figure this one out for a few hours to no avail.

 

I set up a macro to check if a file is locked, leveraging the Run Command tool and a batch script.

 

Relative directoryRelative directory

This works beautifully when I run this macro from my machine, since I have write access to the working directory.

 

Local working directoryLocal working directory

But when I try to run this same macro from the server (i.e. I call this macro from a workflow that is saved into our company gallery and is run from that server machine), the Run Command throws errors (generally "1"), which suggest that one or more of the files can't be created or read.

 

When I checked what the working directory is for the server machine, I see that it is a sub-folder under ProgramData/Alteryx which I apparently am unable to write to or read from.

Server working directoryServer working directory

So then I thought that I could specify a distinct network directory that I know the server box has access to.  And while this works fine for the Write Source and Read Results sections, I am unable to use a UNC path in my command line argument.

 

run4.png

 

 

So my question is: how can I set up this macro so that it can either a) always use a relative path that the machine running the workflow actually has write access to, or b) use a defined network path without running into the UNC issue?

Highlighted
16 - Nebula
16 - Nebula

A trick I have used in the past to run a UNC path batch file is to use the following as the command arguments:

 

/C "PUSHD \\tableaunetapp.seagate.com\tableau_prod\SMC\Staging & FileLockCheck.bat"

 

I believe it should work on most versions of WIndows... 

Highlighted
16 - Nebula
16 - Nebula

@mix_pix Just my two cents, but try using the %Engine.TempFilePath% and calling the bat directly:

Capture.PNG

That seemed to resolve the issues on my side (and hopefully it's the same for you). I was able to figure out the issue by adding a pause statement to the bat and then not making it silent. Then I got this from the cmd prompt:

Capture.PNG

By having it write out the bat to a relative path, it's actually using the macro's relative path. So the bat file is called from my macro repository, which I have in the UNC form. Apparently the cmd prompt balks at that and then uses C:\Windows as the working directory. While I'm using the Engine.tempfilepath constant, you could also use Engine.ModuleDirectory constant.

 

Hope that helps!

Highlighted
10 - Fireball

I did try that (although my syntax was a bit different than yours, i.e. the & vs a \ prior to the file name), but the result is the same in either case: the workflow fails with the error message "The external program "c:\windows\system32\cmd.exe" returned an error code: 255 (Tool Id: 30)"

 

Your syntax works perfectly fine when I run the workflow on my local machine after I've saved it somewhere.  But if I paste the same tools into a new workflow and don't save it (i.e. it is using the workflow constants as a temporary file location), I get the same 255 error.

 

So it would appear that these temporary workflow directories are preventing the bat file from being written and subsequently read in.  Not sure how to get around that.

Highlighted
10 - Fireball

Hi Patrick,

 

Thanks for the suggestion.  The problem is that whenever I reference either of those constants (the TempFilePath or the WorkflowDirectory), I get errors - either a 1 or a 255, both of which seem to suggest that the run command can't locate one or more of the files.

 

I don't get any of these errors when I run the workflow from my local machine after I've saved it somewhere explicit.  But if it's a new unsaved workflow, or a workflow that I save to the gallery, I can't get this run command to execute.

 

file not found.png

Highlighted
16 - Nebula
16 - Nebula

@mix_pix hmm...it looks like the messages show that the bat is always written correct? If that's the case, I would change your formula tool so that instead of writing your results file to a relative path (results.txt) you write it to to the same temp directory (%ENGINE.tempfilepath%results.txt) as the bat itself. I ran the attached just fine on my server. The yxzp didn't include all the nested macros so you'll have to add those back in.

 

 

 

Highlighted
10 - Fireball

So, more weirdness.  When I update the Run Command tool per your example, I get an error when saving it to the Gallery, and naturally I get the same error when I try to run it from there.

 

save error.png

 

When I go remove the Read Results file (e.g. results.txt), the workflow runs without issue, even though I am writing to and reading from the same %temp% directory as I was using for the Read Results file.

 

runs fine.png

 

But when I add the Read Results file, I get the error.

 

results error.png

 

So it is completely baffling to me that the %temp% directory works for the Write Source and Command Arguments but not for the Read Results.  Any insight as to why that might happen?

 

Highlighted
16 - Nebula
16 - Nebula

@mix_pix and I were able to debug over a webex. When working with an unsaved workflow or on the server, the .bat was being run from an unexpected directory. There are at least 3 different ways to fix this

1) specify a working directory like %Engine.WorkflowDirectory%:

Capture.PNG

or

2) change the line in the .bat command to write out to a specified directory instead of relative results.txt:

Change this:

//"@echo off"+"
//"+
"2>nul ("+"
"
+"  >>"+'"'+[File]+'"'+" echo off"+"
"
+") && (echo file is not locked > results.txt) || (echo file is locked >results.txt)"


to this:
//"@echo off"+"
//"+
"2>nul ("+"
"
+"  >>"+'"'+[File]+'"'+" echo off"+"
"
+") && (echo file is not locked > %ENGINE.WorkflowDirectory%results.txt) || (echo file is locked >%ENGINE.WorkflowDirectory%results.txt)"

By modifying the results.txt from relative to our workflow directory

or 3) You could also change everything to write out to tempspace in an abundance of caution to make sure it all lines up:

Capture2.PNG

Capture.PNG

 

Hope that helps anybody else! It was difficulty to comprehend because the initial setup worked just fine. 

Highlighted
10 - Fireball

Thanks for your help Patrick.  Very much appreciated. :-)

 

I've updated my macro based on the work we did and attached it to my other post, in case you want to use it.

Highlighted
8 - Asteroid

 

Hey @patrick_digan ! Am looking for similar help as am very much new to scripting and using Alteryx. 

 

Problem statement: Am trying to run a python code to download email attachments from one of our mailbox and the Run command tool is not working as expected.

 

Additional info: The code has been written in Python v 2.7.14 where as the pre installed python setup inside Alteryx seems to be v 3.6. So am unable to run the script via the latest. With some help the code was modified for v 3.6 and it works fine fetching the information required via the IDE.  But when I try to use this code in Alteryx using a Run Command it fails and throws an error. As this is my first try using the run Command tool am not very sure if my cofigs or the directory settings are correct. 

 

Any sort of guidance will greatly help to achieve this solution. Any thought?  Very much looking forward. 

 

Below the screen shots for reference 

 

Run command configRun command configworkflow config.PNG

Labels