C# code to run python script using arguments and get output into data item stage in object studio
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
28-02-20 07:24 AM
I am new to Blue Prism and I want to run a python script from coding stage using C# by passing arguments and storing its output in the data variable.
Please elaborate the code
Thanks in advance
- Vishal Salvankar
------------------------------
Vishal Salvankar
------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
28-02-20 01:58 PM
------------------------------
Dave Morris
3Ci @ Southern Company
Atlanta, GA
------------------------------
Dave Morris, 3Ci at Southern Company
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
06-03-20 04:53 AM
I found the solution to call the python script using C# code
string result="";string result="";string ErrorMsg="";bool isError=true;try{ProcessStartInfo start = new ProcessStartInfo(); start.FileName = Python_Executable_File_Path; start.Arguments = Script_Path; start.UseShellExecute = false; start.RedirectStandardInput = true; start.RedirectStandardOutput = true; using(Process process = Process.Start(start)) { using (StreamWriter sw = process.StandardInput) { sw.WriteLine(Input); sw.Close(); }
using(StreamReader reader = process.StandardOutput) { result = reader.ReadToEnd(); } } } catch (Exception exp) { ErrorMsg=exp.Message; isError=false;}
Exception=ErrorMsg;Success=isError; ScriptOutput= result;
The above code needs to be used in the code stage in Object Studio.
The input and output parameters need to be given accordingly.
Do not forget to include namespaces in the Initialization page of the Object
Thanks
------------------------------
Vishal Salvankar
------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
06-03-20 08:35 AM
I see you've already figured out some C# to get you what you need. I did want to point out that there is now a VBO available on the DX that can assist with executing Python scripts. You can find it here:
https://digitalexchange.blueprism.com/dx/entry/9648/solution/blue-prism---script-execution-vbo
cheers,
------------------------------
Eric Wilson
Director, Partner Integrations for Digital Exchange
Blue Prism
------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
21-06-20 04:55 PM
I tried running the python script with the Environment VBO. However, I keep getting an error: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf3 in position 50: invalid continuation byte when running the python script. But when I run the script via CMD,i.e outside Blueprism, it runs successfully.
Please I need help resolving this issue.
Thanks.
------------------------------
Shakirat Jimoh
programmer
Waje smart solution
Africa/Lagos
------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
21-06-20 05:36 PM
------------------------------
Eric Wilson
Director, Partner Integrations for Digital Exchange
Blue Prism
------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
21-06-20 06:26 PM
Hi Eric
Find above the image for the VBO Settings.
------------------------------
Shakirat Jimoh
programmer
Waje smart solution
Africa/Lagos
------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
21-06-20 07:06 PM
C:\Users\blueprism\Documents\GT_Solution.exe "C:\SomeFilePath" -f
Typically, executing a Python script on Windows involves a reference to the Python interpreter which would look something like this:
C:\python3 HelloWorld.py [Parameters]
There is an actual Python execution VBO available on the DX. Have you tried that as opposed to the Utility - Environment VBO?
One thing I would recommend is to change your parameter data to something like this:
Chr(34) & [Destination FilePath] & Chr(34) & " -f"
I don't think this change will impact the error you're seeing, but it will make you're data easier to read and maintain.
Cheers,
------------------------------
Eric Wilson
Director, Partner Integrations for Digital Exchange
Blue Prism
------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
22-06-20 05:46 AM
------------------------------
Mayank Goyal
------------------------------
