Advertisement
Guest User

Livoks prototype

a guest
Apr 26th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.85 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7. using System.Diagnostics;
  8.  
  9. namespace pythontestigen
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.  
  16.             Console.WriteLine("I have started");
  17.  
  18.             launchPython();         //Open the python script
  19.  
  20.             createDataFile();       //Make new datafile for Python  
  21.  
  22.             getChoiceFile();
  23.  
  24.             Console.ReadKey();
  25.         }
  26.  
  27.         static void createDataFile()
  28.         {
  29.             var fileGive = File.Create(@"toPython.txt");
  30.             fileGive.Close();
  31.  
  32.             writeDataFile();        //Put data in the txt file
  33.         }
  34.         static void getChoiceFile()
  35.         {
  36.             while (!File.Exists("toCs.txt"))
  37.             {
  38.                 //Nothing happens here, im just waiting for the file to exist
  39.             }
  40.            
  41.             // Open the file to read from.
  42.             FileInfo fileGet = new FileInfo(@"toCs.txt");
  43.  
  44.             Console.WriteLine("C#: i am reading a file");
  45.  
  46.             using (StreamReader sr = fileGet.OpenText())
  47.             {
  48.                 string s = "Data from Python goes here";
  49.                 while ((s = sr.ReadLine()) != null)
  50.                 {
  51.                     Console.WriteLine(s);
  52.                 }
  53.             }
  54.         }
  55.  
  56.         private static void writeDataFile()
  57.         {
  58.             using (TextWriter tw = new StreamWriter(@"toPython.txt"))
  59.             {
  60.                 tw.WriteLine("A snake reads this file");
  61.                 tw.WriteLine("hiiiiiissssssss hiiiiiissssssss");
  62.                 tw.WriteLine("You are snek");
  63.                 tw.WriteLine("Boop Doot Snoot");
  64.             }
  65.            
  66.         }
  67.  
  68.         private static void launchPython()
  69.         {
  70.             // full path of python interpreter  
  71.             string python = @"C:\Users\T7536\AppData\Local\Programs\Python\Python36\python.exe";
  72.  
  73.             // python app to call  
  74.             string myPythonApp = "addem.py";
  75.  
  76.             // Create new process start info
  77.             ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(python);
  78.  
  79.             // make sure we can read the output from stdout
  80.             myProcessStartInfo.UseShellExecute = false;
  81.             myProcessStartInfo.RedirectStandardOutput = true;
  82.  
  83.             // start python app with 3 arguments  
  84.             // 1st argument is pointer to itself, 2nd and 3rd are actual arguments we want to send
  85.             myProcessStartInfo.Arguments = myPythonApp;// + " " + x + " " + y;
  86.  
  87.             Process myProcess = new Process();
  88.             // assign start information to the process
  89.             myProcess.StartInfo = myProcessStartInfo;
  90.  
  91.             // start process
  92.             myProcess.Start();
  93.         }
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement