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.

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

I'll try it out, thanks. But what if it's quite a big script, won't it slow the process down?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.