You have to follow these steps to achieve this.
Host that python file in CGI, lets say link is http://localhost/cgi-bin/test.py and invoke that using WebClient and get output. Following are code for invoking URL using WebClient.
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
WebClient client = new WebClient();
string reply = client.DownloadString("http://localhost/cgi-bin/test.py"); // address = CGI hosted URL
TextBox1.Text = reply;
}
ELSE
Assumption: You have python installed in windows system.
- Save python script to a file , say abc.py.
- You can directly execute python script, using this
"c:\python26\python.exe" "abc.py". We will use this in next step.
- Using process execution, we can execute the above command from C# and get output. Example-
var proc = new Process {
StartInfo = new ProcessStartInfo {
FileName = "c:\python26\python.exe",
Arguments = "abc.py",
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};
proc.Start();
while (!proc.StandardOutput.EndOfStream) {
string line = proc.StandardOutput.ReadLine();
// do something with line
TextBox1.Text = line;
}
OR - use this link http://blog.luisrei.com/articles/flaskrest.html - this shows , how to make python code REST based thing, and you can invoke directly that REST API in asp.net code.