Click here to Skip to main content
15,888,279 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
i am using below code
to read python file.
C#
ProcessStartInfo start = new ProcessStartInfo();
          //  start.FileName = @"C:\Users\rahuls1\Desktop\DEmo\Temp\demo.py";
            start.FileName = @"C:\Users\rahuls1\Desktop\DEmo\Temp\demo.py";
           // start.Arguments = m_strApplStartupPath;
            start.ErrorDialog = false;
            start.UseShellExecute = false;
            start.RedirectStandardError = true;
            start.RedirectStandardInput = true;
            start.RedirectStandardOutput = true;
            start.CreateNoWindow = true;
            using (Process process = Process.Start(start))
            {
                using (StreamReader reader = process.StandardOutput)
                {
                    string result = reader.ReadToEnd();

                }
            }

but i am getting this error
The specified executable is not a valid application for this OS platform
please help me on this.
Posted

This error is telling you that the Python executable is not present in the %PATH% command. What you could do here is add the following code:
C#
start.FileName = @"c:\PathToPython\Python";
start.Arguments = @"C:\Users\rahuls1\Desktop\DEmo\Temp\demo.py";
 
Share this answer
 
Comments
rahuls1 27-Jan-14 5:20am    
now error is that system could not find the specified File after adding the Code..
Pete O'Hanlon 27-Jan-14 5:23am    
Have you added the right path to the python executable?
rahuls1 27-Jan-14 5:32am    
python executabel will be in starT.FILENAME..
rahuls1 27-Jan-14 5:32am    
ProcessStartInfo start = new ProcessStartInfo();
// start.FileName = @"C:\Users\rahuls1\Desktop\DEmo\Temp\demo.py";
start.FileName= @"c:\Users\rahuls1\Desktop\DEmo\Temp\demo.exe";
start.Arguments = @"C:\Users\rahuls1\Desktop\DEmo\Temp\demo.py";
start.ErrorDialog = false;
start.UseShellExecute = false;
start.RedirectStandardError = true;
start.RedirectStandardInput = true;
start.RedirectStandardOutput = true;
start.CreateNoWindow = true;

using (Process process = Process.Start(start))
{
using (StreamReader reader = process.StandardOutput)
{
string result = reader.ReadToEnd();

}
}
THIS IS THE CODE I AM USING..
Pete O'Hanlon 27-Jan-14 5:36am    
start.FileName isn't pointing to PYTHON though. I thought I was clear in telling you that it had to point to the python executable.
That is the code for launching a Python script. It doesn't work if Python is not installed on your system.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900