I am trying to run a python script from my C# application.
Attached is a snippet of my code:
string output = "";
ProcessStartInfo Script = new ProcessStartInfo();
Script.FileName = File;
Script.Arguments = XMLargs;
Script.UseShellExecute = false;
Script.RedirectStandardOutput = true;
Script.RedirectStandardError = true;
try
{
using (Process process = Process.Start(Script))
{
using (StreamReader reader = process.StandardOutput)
{
output = reader.ReadToEnd();
}
}
}
catch(Exception e)
{
//Error message
}
However, every time that I try to run this, I get this error:
The Specified Executable is not valid for this OS
This happens regardless of what Python script I use.
Further, I can run all Python scripts from the command prompt with no issues.
My development environment is Visual Studio 2015, and I installed the updated Python Tools for Visual Studio 2015. I'm using 64 bit Python 2.7.
Is there something wrong with the code above? Or is there something that I need to work out in Visual Studio?
try
Script.FileName = {path to python.exe};
Script.Arguments = {path to your py script} + {args};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.