<?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: Python Scripts with Input and Output in Product Forum</title>
    <link>https://community.blueprism.com/t5/Product-Forum/Python-Scripts-with-Input-and-Output/m-p/47790#M3457</link>
    <description>Hi All&lt;BR /&gt;Thanks for the suggestions.&lt;BR /&gt;I wrote a small C# script using Process.start, which takes inputs as Python interpreter, Python script to execute and then arguments if any.&lt;BR /&gt;The Python script also need to be written in a supporting way to have stdout and stderr.&amp;nbsp;&lt;BR /&gt;C# code :&lt;BR /&gt;// e.g. start.FileName = "C:\\Python27\\python.exe";&lt;BR /&gt;// Argument 0 = Path to your python script (example : "C:\\add_them.py")&lt;BR /&gt;// Argument 1 = first arguement taken from&amp;nbsp; C#'s main method's args variable&lt;BR /&gt;// Argument 2 = second argument.... and so on...&lt;BR /&gt;//&lt;BR /&gt;// pass these to your Arguments property of your ProcessStartInfo instance&lt;BR /&gt;// In the Python script sys.argv[0] will contain the script name.&lt;BR /&gt;// ******************************************************&lt;BR /&gt;ProcessStartInfo start = new ProcessStartInfo();&lt;BR /&gt;start.FileName = Python_Executable_Path;&lt;BR /&gt;start.Arguments = Python_Script_Path + " " + Python_Arguments;&lt;BR /&gt;start.UseShellExecute = false;&lt;BR /&gt;start.RedirectStandardOutput = true;&lt;BR /&gt;start.RedirectStandardError = true;&lt;BR /&gt;using (Process process = Process.Start(start))&lt;BR /&gt;{ &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; using (StreamReader reader = process.StandardOutput,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;reader_err = process.StandardError )&lt;BR /&gt;&amp;nbsp; &amp;nbsp; { &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; string error = reader_err.ReadToEnd(); &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Error_Output = error; &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; string result = reader.ReadToEnd(); &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; JSON_Output = result;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Sample Python :&lt;BR /&gt;## Write Print/stdout.write statements only&amp;nbsp; when necessary&lt;BR /&gt;## Write Print/stdout.write statements only&amp;nbsp; when necessary&lt;BR /&gt;## Avoid intermediate prints used for debugging in final version&lt;BR /&gt;## Otherwise it will be captured as output along with JSON&lt;BR /&gt;## sys.argv[0] contains script name&lt;BR /&gt;## import sys and json lib&lt;BR /&gt;/* ================ Sample Python Script ====================&lt;BR /&gt;import sys&lt;BR /&gt;import json&lt;BR /&gt;cnt = len(sys.argv) - 1&lt;BR /&gt;#print("Arguments received: {}".format(cnt)) ==&amp;gt;&amp;gt; AVOID THIS!!&lt;BR /&gt;sum1 = 0&lt;BR /&gt;if (cnt &amp;lt; 1 &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&amp;nbsp; &amp;nbsp; &lt;BR /&gt;&amp;nbsp; &amp;nbsp; sys.stderr.write("No arguments were passed..!!")&lt;BR /&gt;&amp;nbsp; &amp;nbsp; sys.stderr.flush()&lt;BR /&gt;&amp;nbsp; &amp;nbsp; sys.exit(0)&lt;BR /&gt;else:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; j = 1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; for i in sys.argv:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (j &amp;gt; 1):&amp;nbsp; &amp;nbsp;# skip the first argument&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sum1 = sum1 + int(i)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; j = j + 1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; outdict = {'Name':'John', 'Grade':'Consultant', 'Param cnt':cnt, 'Points':sum1}&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; json_string = json.dumps(outdict)&lt;BR /&gt;sys.stdout.write(json_string)&lt;BR /&gt;sys.stdout.flush()&lt;BR /&gt;sys.exit(0)&lt;BR /&gt;====================================================&amp;nbsp; */&lt;BR /&gt;&lt;BR /&gt;------------------------------&lt;BR /&gt;Nikhil Sathe&lt;BR /&gt;Sr Consultant&lt;BR /&gt;Capgemini Technology Services&lt;BR /&gt;------------------------------&lt;BR /&gt;</description>
    <pubDate>Mon, 13 Jan 2020 05:54:00 GMT</pubDate>
    <dc:creator>NikhilSathe</dc:creator>
    <dc:date>2020-01-13T05:54:00Z</dc:date>
    <item>
      <title>Python Scripts with Input and Output</title>
      <link>https://community.blueprism.com/t5/Product-Forum/Python-Scripts-with-Input-and-Output/m-p/47787#M3454</link>
      <description>Hi&lt;BR /&gt;I want to execute a Python script and take back the output it gives (may be text).&lt;BR /&gt;Earlier I downloaded the latest Environment utility having action "Start Process Read Stderr ad Stdout".&lt;BR /&gt;When I execute the script using the "Start Process" action it executes, but it is not able to accept any response.&lt;BR /&gt;The new action is giving me error "Internal : Could not execute code stage because exception thrown by code stage: The specified executable is not a valid application for this OS platform."&lt;BR /&gt;I am having 64 bit Windows 10 laptop.&lt;BR /&gt;&lt;BR /&gt;Python code:&lt;BR /&gt;import sys&lt;BR /&gt;sys.stdout.write('Returning from Python\n')&lt;BR /&gt;sys.stdout.flush()&lt;BR /&gt;sys.exit(0)&lt;BR /&gt;&lt;BR /&gt;Is there any other way to it? I know writing to a file is an option, but I am taking it as a last resort.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;------------------------------&lt;BR /&gt;Nikhil Sathe&lt;BR /&gt;Sr Consultant&lt;BR /&gt;Capgemini Technology Services&lt;BR /&gt;------------------------------&lt;BR /&gt;</description>
      <pubDate>Fri, 03 Jan 2020 11:51:00 GMT</pubDate>
      <guid>https://community.blueprism.com/t5/Product-Forum/Python-Scripts-with-Input-and-Output/m-p/47787#M3454</guid>
      <dc:creator>NikhilSathe</dc:creator>
      <dc:date>2020-01-03T11:51:00Z</dc:date>
    </item>
    <item>
      <title>RE: Python Scripts with Input and Output</title>
      <link>https://community.blueprism.com/t5/Product-Forum/Python-Scripts-with-Input-and-Output/m-p/47788#M3455</link>
      <description>Hi Nikhil&lt;BR /&gt;&lt;BR /&gt;There is a bit of twist but you could run this python script through CMD (Dos Prompt) and in the start process create a batch file to execute this script. In a way if you see it would be a part of your BOT but still would be outside of your BOT operation and would work exactly as a silos operation.&lt;BR /&gt;&lt;BR /&gt;Please let me know if this helps &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Best Regards&lt;BR /&gt;Mandar Brahme&lt;BR /&gt;&lt;BR /&gt;------------------------------&lt;BR /&gt;Mandar Brahme&lt;BR /&gt;Infrastructure Manager&lt;BR /&gt;Cognizant Technology Solutions&lt;BR /&gt;Asia/Kolkata&lt;BR /&gt;------------------------------&lt;BR /&gt;</description>
      <pubDate>Tue, 07 Jan 2020 06:10:00 GMT</pubDate>
      <guid>https://community.blueprism.com/t5/Product-Forum/Python-Scripts-with-Input-and-Output/m-p/47788#M3455</guid>
      <dc:creator>MandarBrahme</dc:creator>
      <dc:date>2020-01-07T06:10:00Z</dc:date>
    </item>
    <item>
      <title>RE: Python Scripts with Input and Output</title>
      <link>https://community.blueprism.com/t5/Product-Forum/Python-Scripts-with-Input-and-Output/m-p/47789#M3456</link>
      <description>Hi Nikhil&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Please Check Input parameter for the action:&lt;BR /&gt;Arguments: Python file path&lt;BR /&gt;Process Name: Python Exe path&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Shubham Jangam&lt;BR /&gt;&lt;BR /&gt;------------------------------&lt;BR /&gt;Shubham Jangam&lt;BR /&gt;RPA Developer&lt;BR /&gt;Webonise Lab&lt;BR /&gt;Asia/Kolkata&lt;BR /&gt;------------------------------&lt;BR /&gt;</description>
      <pubDate>Tue, 07 Jan 2020 07:01:00 GMT</pubDate>
      <guid>https://community.blueprism.com/t5/Product-Forum/Python-Scripts-with-Input-and-Output/m-p/47789#M3456</guid>
      <dc:creator>ShubhamJangam</dc:creator>
      <dc:date>2020-01-07T07:01:00Z</dc:date>
    </item>
    <item>
      <title>RE: Python Scripts with Input and Output</title>
      <link>https://community.blueprism.com/t5/Product-Forum/Python-Scripts-with-Input-and-Output/m-p/47790#M3457</link>
      <description>Hi All&lt;BR /&gt;Thanks for the suggestions.&lt;BR /&gt;I wrote a small C# script using Process.start, which takes inputs as Python interpreter, Python script to execute and then arguments if any.&lt;BR /&gt;The Python script also need to be written in a supporting way to have stdout and stderr.&amp;nbsp;&lt;BR /&gt;C# code :&lt;BR /&gt;// e.g. start.FileName = "C:\\Python27\\python.exe";&lt;BR /&gt;// Argument 0 = Path to your python script (example : "C:\\add_them.py")&lt;BR /&gt;// Argument 1 = first arguement taken from&amp;nbsp; C#'s main method's args variable&lt;BR /&gt;// Argument 2 = second argument.... and so on...&lt;BR /&gt;//&lt;BR /&gt;// pass these to your Arguments property of your ProcessStartInfo instance&lt;BR /&gt;// In the Python script sys.argv[0] will contain the script name.&lt;BR /&gt;// ******************************************************&lt;BR /&gt;ProcessStartInfo start = new ProcessStartInfo();&lt;BR /&gt;start.FileName = Python_Executable_Path;&lt;BR /&gt;start.Arguments = Python_Script_Path + " " + Python_Arguments;&lt;BR /&gt;start.UseShellExecute = false;&lt;BR /&gt;start.RedirectStandardOutput = true;&lt;BR /&gt;start.RedirectStandardError = true;&lt;BR /&gt;using (Process process = Process.Start(start))&lt;BR /&gt;{ &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; using (StreamReader reader = process.StandardOutput,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;reader_err = process.StandardError )&lt;BR /&gt;&amp;nbsp; &amp;nbsp; { &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; string error = reader_err.ReadToEnd(); &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Error_Output = error; &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; string result = reader.ReadToEnd(); &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; JSON_Output = result;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Sample Python :&lt;BR /&gt;## Write Print/stdout.write statements only&amp;nbsp; when necessary&lt;BR /&gt;## Write Print/stdout.write statements only&amp;nbsp; when necessary&lt;BR /&gt;## Avoid intermediate prints used for debugging in final version&lt;BR /&gt;## Otherwise it will be captured as output along with JSON&lt;BR /&gt;## sys.argv[0] contains script name&lt;BR /&gt;## import sys and json lib&lt;BR /&gt;/* ================ Sample Python Script ====================&lt;BR /&gt;import sys&lt;BR /&gt;import json&lt;BR /&gt;cnt = len(sys.argv) - 1&lt;BR /&gt;#print("Arguments received: {}".format(cnt)) ==&amp;gt;&amp;gt; AVOID THIS!!&lt;BR /&gt;sum1 = 0&lt;BR /&gt;if (cnt &amp;lt; 1 &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&amp;nbsp; &amp;nbsp; &lt;BR /&gt;&amp;nbsp; &amp;nbsp; sys.stderr.write("No arguments were passed..!!")&lt;BR /&gt;&amp;nbsp; &amp;nbsp; sys.stderr.flush()&lt;BR /&gt;&amp;nbsp; &amp;nbsp; sys.exit(0)&lt;BR /&gt;else:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; j = 1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; for i in sys.argv:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (j &amp;gt; 1):&amp;nbsp; &amp;nbsp;# skip the first argument&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sum1 = sum1 + int(i)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; j = j + 1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; outdict = {'Name':'John', 'Grade':'Consultant', 'Param cnt':cnt, 'Points':sum1}&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; json_string = json.dumps(outdict)&lt;BR /&gt;sys.stdout.write(json_string)&lt;BR /&gt;sys.stdout.flush()&lt;BR /&gt;sys.exit(0)&lt;BR /&gt;====================================================&amp;nbsp; */&lt;BR /&gt;&lt;BR /&gt;------------------------------&lt;BR /&gt;Nikhil Sathe&lt;BR /&gt;Sr Consultant&lt;BR /&gt;Capgemini Technology Services&lt;BR /&gt;------------------------------&lt;BR /&gt;</description>
      <pubDate>Mon, 13 Jan 2020 05:54:00 GMT</pubDate>
      <guid>https://community.blueprism.com/t5/Product-Forum/Python-Scripts-with-Input-and-Output/m-p/47790#M3457</guid>
      <dc:creator>NikhilSathe</dc:creator>
      <dc:date>2020-01-13T05:54:00Z</dc:date>
    </item>
  </channel>
</rss>

