Advertisement
dereksir

Untitled

Dec 5th, 2023
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 KB | None | 0 0
  1. using System.Diagnostics;
  2.  
  3. class Program
  4. {
  5.     static void Main()
  6.     {
  7.         // Create a Process object
  8.         using (Process process = new Process())
  9.         {
  10.             // Set the Python interpreter as the filename
  11.             process.StartInfo.FileName = "python";
  12.  
  13.             // Specify the path to your Python script as arguments
  14.             process.StartInfo.Arguments = "C:\\Path\\to\\your\\script.py";
  15.  
  16.             // Configure process settings
  17.             process.StartInfo.UseShellExecute = false; // Don't use the operating system shell
  18.             process.StartInfo.RedirectStandardOutput = true; // Redirect standard output
  19.             process.StartInfo.CreateNoWindow = true; // Don't create a window for the process
  20.  
  21.             // Start the process
  22.             process.Start();
  23.  
  24.             // Read the standard output
  25.             string output = process.StandardOutput.ReadToEnd();
  26.  
  27.             // Wait for the process to exit
  28.             process.WaitForExit();
  29.  
  30.             // Process the output
  31.             Console.WriteLine(output);
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement