0

I have my script written in Python and GUI for it in C#. That is why I'd like to run Python from C# (I have to use the original Python version because of various modules which i.e. IronPython does not support). To secure the script I embedded it into the .exe file. Now, how can I get the script path? My previous code:

    string python = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\python\python.exe";

    // NOW it obviously does not work
    string scriptPath = @"C:\..\script.py";

    ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(python);
    myProcessStartInfo.UseShellExecute = false;
    myProcessStartInfo.RedirectStandardOutput = true;
    myProcessStartInfo.Arguments = scriptPath;
    Process myProcess = new Process();
    myProcess.StartInfo = myProcessStartInfo;
    myProcess.Start();

Assembly.GetExecutingAssembly().GetManifestResourceStream(...) won't be useful here because I don't want stream (or do I?), just the path.

Mike
  • 373
  • 4
  • 10

1 Answers1

1

If the script is an embedded resource (How to read embedded resource text file), you could read it as string and use the -c parameter of python.exe

  • I'll try it out, thanks. But what if it's quite a big script, won't it slow the process down? – Mike Mar 14 '19 at 17:39