<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Iterate a script that calls to an .exe for variables? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/iterate-a-script-that-calls-to-an-exe-for/m-p/482027#M37685</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;So setting the parameters as constants would work even thought the .exe will be looking for them to be defined?&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Ideally the code would break down like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;set parameters (except name of featureclass) as constants&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;start iteration within folder on featureclasses&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Run exe with new name but same parameters.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Save to different folder.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; move to next featureclass&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I just wasn't sure, since the .exe is looking for 7 inputs, if it would work.&amp;nbsp;&amp;nbsp; There is nothing coded which would pass the constants to the .exe.&amp;nbsp; I felt like it would still be looking for inputs.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now having thought it through, it makes sense since sys.argv is coming from the script, not the exe.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 11 Jun 2014 22:18:03 GMT</pubDate>
    <dc:creator>TomKearns</dc:creator>
    <dc:date>2014-06-11T22:18:03Z</dc:date>
    <item>
      <title>Iterate a script that calls to an .exe for variables?</title>
      <link>https://community.esri.com/t5/python-questions/iterate-a-script-that-calls-to-an-exe-for/m-p/482025#M37683</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a tool that I would like to run on each file in a folder.&amp;nbsp; The tool runs in arcmap and is a python shell that concocts a command line command that then calls to an .exe.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there a way to hard code within the python script variables the .exe is looking for?&amp;nbsp; There are 7 variables, they will all remain the same aside from the first, which will just change for each FeatureClass.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Some of the code is as follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[HTML]### maybe an output file name was selected&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if sys.argv[5] != "#":&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; command.append("-o")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; command.append('"'+sys.argv[5]+'"')&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;### maybe an output directory was selected&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if sys.argv[6] != "#":&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; command.append("-odir")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; command.append('"'+sys.argv[6]+'"')&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;### maybe an output appendix was selected&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if sys.argv[7] != "#":&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; command.append("-odix")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; command.append('"'+sys.argv[7]+'"')[/HTML]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Jun 2014 21:09:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/iterate-a-script-that-calls-to-an-exe-for/m-p/482025#M37683</guid>
      <dc:creator>TomKearns</dc:creator>
      <dc:date>2014-06-11T21:09:04Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate a script that calls to an .exe for variables?</title>
      <link>https://community.esri.com/t5/python-questions/iterate-a-script-that-calls-to-an-exe-for/m-p/482026#M37684</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You could either place the command arguments in your script as constants or pass them in via tool parameters.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;# Option 1 - Get feature class from tool parameter arg1 = arcpy.GetParameterAsText(0)&amp;nbsp; # Define static parameters ARG2 = "ABC" ARG3 = "123" ARG4 = "456" ARG5 = "#" ARG6 = "XYZ" ARG7 = "#"&amp;nbsp; # Process parameters into command line if ARG2 != "#": &amp;nbsp;&amp;nbsp;&amp;nbsp; command.append("-o") &amp;nbsp;&amp;nbsp;&amp;nbsp; command.append('"'+ARG2+'"')&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Note - there is no particular language construct to declare a constant in python, it is just a variable. They are typically declared as variables with uppercase names.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;# Option 2 - Get all variables from tool parameters arg1 = arcpy.GetParameterAsText(0) arg2 = arcpy.GetParameterAsText(1) arg3 = arcpy.GetParameterAsText(2) arg4 = arcpy.GetParameterAsText(3) arg5 = arcpy.GetParameterAsText(4) arg6 = arcpy.GetParameterAsText(5) arg7 = arcpy.GetParameterAsText(6)&amp;nbsp; # Process parameters into command line if arg2 != "#": &amp;nbsp;&amp;nbsp;&amp;nbsp; command.append("-o") &amp;nbsp;&amp;nbsp;&amp;nbsp; command.append('"'+arg2+'"')&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The second option allows you to change the parameters without editing the script. However, you will need to create all of the parameters in the tool properties and give them default values.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If they are constant values then I would probably go with option 1.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Owen&lt;/SPAN&gt;&lt;BR /&gt;&lt;A _jive_internal="true" class="" href="https://community.esri.com/www.spatialxp.com.au"&gt;www.spatialxp.com.au&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Jun 2014 22:07:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/iterate-a-script-that-calls-to-an-exe-for/m-p/482026#M37684</guid>
      <dc:creator>OwenEarley</dc:creator>
      <dc:date>2014-06-11T22:07:35Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate a script that calls to an .exe for variables?</title>
      <link>https://community.esri.com/t5/python-questions/iterate-a-script-that-calls-to-an-exe-for/m-p/482027#M37685</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;So setting the parameters as constants would work even thought the .exe will be looking for them to be defined?&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Ideally the code would break down like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;set parameters (except name of featureclass) as constants&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;start iteration within folder on featureclasses&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Run exe with new name but same parameters.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Save to different folder.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; move to next featureclass&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I just wasn't sure, since the .exe is looking for 7 inputs, if it would work.&amp;nbsp;&amp;nbsp; There is nothing coded which would pass the constants to the .exe.&amp;nbsp; I felt like it would still be looking for inputs.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now having thought it through, it makes sense since sys.argv is coming from the script, not the exe.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Jun 2014 22:18:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/iterate-a-script-that-calls-to-an-exe-for/m-p/482027#M37685</guid>
      <dc:creator>TomKearns</dc:creator>
      <dc:date>2014-06-11T22:18:03Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate a script that calls to an .exe for variables?</title>
      <link>https://community.esri.com/t5/python-questions/iterate-a-script-that-calls-to-an-exe-for/m-p/482028#M37686</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;sys.argv[] is the list of variables being passed to the python script - with sys.argv[0] being the first argument. The arcpy library has alternate ways of accessing these same variables such as arcpy.GetParameter(0) and arcpy.GetParameterAsText(0).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;These variables can be different to the command line arguments that you are passing to the exe.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It appears that you are basically building up a command string including the arguments that your exe requires.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If the only thing that changes is the feature class parameter you could build the command line with arguments using the string format function.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# define you exe path
exe_path = r"C:\temp\YourApp.exe"

# start iteration within folder on featureclasses
for fc in folder:
&amp;nbsp;&amp;nbsp;&amp;nbsp; cmd = '"{0}" "{1}" "arg2" "arg3" "arg4" "arg5" "arg6" "arg7"'.format(exe_path, fc)
&amp;nbsp;&amp;nbsp;&amp;nbsp; # run your cmd&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Just change the arguments 2-7 with your constant values.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this helps.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Owen&lt;/SPAN&gt;&lt;BR /&gt;&lt;A _jive_internal="true" href="https://community.esri.com/www.spatialxp.com.au" target="_blank"&gt;www.spatialxp.com.au&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:16:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/iterate-a-script-that-calls-to-an-exe-for/m-p/482028#M37686</guid>
      <dc:creator>OwenEarley</dc:creator>
      <dc:date>2021-12-11T21:16:27Z</dc:date>
    </item>
  </channel>
</rss>

