Run Python .PY script from C#

前端 未结 1 1004
误落风尘
误落风尘 2021-01-15 04:34

I have this python code.

import pyodbc
import time

print(\"Hello\")
plexString = \"{call sproc164407_2053096_651466 ()}\"
connectionPlex = pyodbc.connect(\         


        
相关标签:
1条回答
  • 2021-01-15 05:11

    Have you tried executing python.exe with the script as an argument? It may be as simple as the script not properly executing on its own.

    Like This:

    ProcessStartInfo pythonInfo = new ProcessStartInfo();
    Process python;
    pythonInfo.FileName = @"C:\Python27\python.exe";
    pythonInfo.Arguments = @"C:\Visual Studio Projects\PlexStoredProcedures\PlexStoredProcedures\PlexStoredProcedures.pyw";
    pythonInfo.CreateNoWindow = false;
    pythonInfo.UseShellExecute = true;
    
    Console.WriteLine("Python Starting");
    python = Process.Start(pythonInfo);
    python.WaitForExit();
    python.Close();
    
    0 讨论(0)
提交回复
热议问题