Вызов скрипта python
Добавлено: 28 июл 2016, 15:19
				
				Здравствуйте, создал отчёт с помощью дизайнера, можно ли в него добавить кнопку через которую он будет запускать определённый скрипт на python.
			Создание отчетов и дашбордов в ASP.NET, ASP.NET MVC, .NET Core, Blazor, Angular, PHP, Python, WPF, JavaScript, и Java приложениях и сервисах.
https://forum.stimulsoft.ru/
Код: Выделить всё
import sys
a = int(sys.argv[1]) 
b = int(sys.argv[2])
print (a+b)Код: Выделить всё
    internal string CallPythonScript(int a, int b, string scriptPath)
    {
      string python = @"C:\Users\leon\AppData\Local\Continuum\Anaconda3\python.exe"; // python exe path
      // create new process start info
      ProcessStartInfo startInfo = new ProcessStartInfo(python)
      {
        UseShellExecute = false,
        RedirectStandardOutput = true,
        Arguments = string.Format("{0} {1} {2}", scriptPath, a, b)
      };
      Process process = new Process()
      {
        StartInfo = startInfo
      };
      // start the process
      process.Start();
      // read output value
      StreamReader myStreamReader = process.StandardOutput;
      string result = myStreamReader.ReadLine();
      // wait process to exit
      process.WaitForExit();
      process.Close();
      return result;
    }Код: Выделить всё
using System;
using System.IO;
using System.Diagnostics;Код: Выделить всё
// parse values from text boxes
int a = int.Parse(tbTextA.Text);
int b = int.Parse(tbTextB.Text);
// execute Python script
string result = CallPythonScript(a, b, @"C:\Temp\sum.py");
// show the result
MessageBox.Show(result);