Question
Sagility pvt Ltd
Sagility pvt Ltd
IN
Sagility pvt Ltd
Posted: Aug 16, 2024
Last activity: Aug 19, 2024
Last activity: 19 Aug 2024 14:39 EDT
Closed
Solved
How to call python script from open span.
I am doing a project for that need to trigger python scripts from pega RPA studio,
is there any way to call a python script from RPA studio?
***Edited by Moderator Marije to change type from Pega Academy to Product***
@JoelPrakashJ2907You may do so using the Process.Start method. You can do this in an automation if you may need to use breakpoints or other debugging tools, or inside a script would work as well. The code is down below the screenshot for easy copying and pasting. If you have a sample script to test with, please post, and I can validate that this works as I have not had any opportunity to execute a python script in an automation, but from my research, this code should work.
To create the ProcessStartInfo, I first added the StartProcess method to the automation and then right-clicked on the blue dot for startInfo and selected "create instance". You can then drag the blue dot out of the StartProcess method to get to the ReadToEnd and WaitForExit methods.
public string RunPythonScript(string fileName, string pathToPythonExe)
{
//fileName = @"C:\sample_script.py";
//pathToPythonExe = @"C:\Python27\python.exe"
@JoelPrakashJ2907You may do so using the Process.Start method. You can do this in an automation if you may need to use breakpoints or other debugging tools, or inside a script would work as well. The code is down below the screenshot for easy copying and pasting. If you have a sample script to test with, please post, and I can validate that this works as I have not had any opportunity to execute a python script in an automation, but from my research, this code should work.
To create the ProcessStartInfo, I first added the StartProcess method to the automation and then right-clicked on the blue dot for startInfo and selected "create instance". You can then drag the blue dot out of the StartProcess method to get to the ReadToEnd and WaitForExit methods.
public string RunPythonScript(string fileName, string pathToPythonExe)
{
//fileName = @"C:\sample_script.py";
//pathToPythonExe = @"C:\Python27\python.exe"
Process proc = new Process();
proc.StartInfo = new ProcessStartInfo(pathToPythonExe, fileName)
{
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
};
proc.Start();
string output = proc.StandardOutput.ReadToEnd();
proc.WaitForExit();
return output;
}