If I correctly understood you want to run the 2 commands in order, first
var pythonCommand1 = "a = 4; print(\"Expected a = 4. Actual a = {} \".format(a))";
and then
var pythonCommand2 = "b=2;print(\"Expected b = 2. Actual b = {} \".format(b));print(\"Expected a = 4. Actual a = \");print(a)";
If this is the case the resulting output will be
Expected a = 4. Actual a = 4
Expected b = 2. Actual b = 2
Expected a = 4. Actual a =
4
You could create a single Python script
a = 4
print("Expected a = 4. Actual a = {} ".format(a))
b=2
print("Expected b = 2. Actual b = {} ".format(b))
print("Expected a = 4. Actual a = ")
print(a)
and then run it from your C# application
using System.Diagnostics;
string pyScript = "script.py";
string pyScriptResult = string.Empty;
using (Process proc = new Process())
{
proc.StartInfo.FileName = "python3";
proc.StartInfo.Arguments = pyScript;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.Start();
proc.WaitForExit();
pyScriptResult = proc.StandardOutput.ReadToEnd();
}
Console.WriteLine(pyScriptResult);
And you'll get the exact same output
dotnet run
Expected a = 4. Actual a = 4
Expected b = 2. Actual b = 2
Expected a = 4. Actual a =
4