Skip to main content

Executing Python Scripts Using Sequentum Enterprise

Sequentum Enterprise provides you an option to use Python as one of its scripting languages, however, if you have already created some useful python scripts for doing any calculations or doing some easy stuff for you using the strong python libraries then you can also use them in Sequentum Enterprise as well.

Here is what all you will need to do.

Below C# code will start a process and assign it to the Python interpreter with the Python program name passed as an argument. The output is parsed as a stream. However, the output can be written to a file instead. The idea is to call the script using the newly initialized process and get its standard output.

public string run_cmd(string args)
{
String pythonscriptToRun = "PYTHON_SCRIPT_NAME_WITH_LOCATION"
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = "PATH_TO_PYTHON_EXE";
start.Arguments = string.Format("\"{0}\" \"{1}\"", pythonscriptToRun, args);
start.UseShellExecute = false;// Do not use OS shell
start.CreateNoWindow = true; // We don't need new window
start.RedirectStandardOutput = true;// Any output, generated by application will be redirected back
start.RedirectStandardError = true; // Any error in standard output will be redirected back (for example exceptions)
using (Process process = Process.Start(start))
{
using (StreamReader reader = process.StandardOutput)
{
string stderr = process.StandardError.ReadToEnd(); // Here are the exceptions from our Python script
string result = reader.ReadToEnd(); // Here is the result of StdOut(for example: print "test")
return result;
}
}
}

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.