Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- using System.Diagnostics;
- namespace pythontestigen
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("I have started");
- launchPython(); //Open the python script
- createDataFile(); //Make new datafile for Python
- getChoiceFile();
- Console.ReadKey();
- }
- static void createDataFile()
- {
- var fileGive = File.Create(@"toPython.txt");
- fileGive.Close();
- writeDataFile(); //Put data in the txt file
- }
- static void getChoiceFile()
- {
- while (!File.Exists("toCs.txt"))
- {
- //Nothing happens here, im just waiting for the file to exist
- }
- // Open the file to read from.
- FileInfo fileGet = new FileInfo(@"toCs.txt");
- Console.WriteLine("C#: i am reading a file");
- using (StreamReader sr = fileGet.OpenText())
- {
- string s = "Data from Python goes here";
- while ((s = sr.ReadLine()) != null)
- {
- Console.WriteLine(s);
- }
- }
- }
- private static void writeDataFile()
- {
- using (TextWriter tw = new StreamWriter(@"toPython.txt"))
- {
- tw.WriteLine("A snake reads this file");
- tw.WriteLine("hiiiiiissssssss hiiiiiissssssss");
- tw.WriteLine("You are snek");
- tw.WriteLine("Boop Doot Snoot");
- }
- }
- private static void launchPython()
- {
- // full path of python interpreter
- string python = @"C:\Users\T7536\AppData\Local\Programs\Python\Python36\python.exe";
- // python app to call
- string myPythonApp = "addem.py";
- // Create new process start info
- ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(python);
- // make sure we can read the output from stdout
- myProcessStartInfo.UseShellExecute = false;
- myProcessStartInfo.RedirectStandardOutput = true;
- // start python app with 3 arguments
- // 1st argument is pointer to itself, 2nd and 3rd are actual arguments we want to send
- myProcessStartInfo.Arguments = myPythonApp;// + " " + x + " " + y;
- Process myProcess = new Process();
- // assign start information to the process
- myProcess.StartInfo = myProcessStartInfo;
- // start process
- myProcess.Start();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement