This site uses different types of cookies, including analytics and functional cookies (its own and from other sites). To change your cookie settings or find out more, click here. If you continue browsing our website, you accept these cookies.
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.
This works beautifully when I run this macro from my machine, since I have write access to the working directory.
Local 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 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.
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?
@mix_pix Just my two cents, but try using the %Engine.TempFilePath% and calling the bat directly:
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:
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.
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.
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.
@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.
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.
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.
But when I add the Read Results file, I get the error.
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?
@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%:
2) change the line in the .bat command to write out to a specified directory instead of relative results.txt:
+" >>"+'"'+[File]+'"'+" echo off"+"
+") && (echo file is not locked > results.txt) || (echo file is locked >results.txt)"
+" >>"+'"'+[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:
Hope that helps anybody else! It was difficulty to comprehend because the initial setup worked just fine.
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.