Py学习  »  Python

从C执行嵌入式Python文件#

Mike • 4 年前 • 993 次点击  

我的脚本是用python和gui编写的,它是用c编写的。这就是为什么我想从c运行python(由于ironpython不支持各种模块,我不得不使用原始的python版本)。为了保护脚本的安全,我将其嵌入到.exe文件中。现在,我怎样才能得到脚本路径? 我以前的代码:

    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(…) 在这里不会有用,因为我不想要stream(或者我想要stream?),就这条路。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/47373
 
993 次点击  
文章 [ 1 ]  |  最新文章 4 年前
user3859852
Reply   •   1 楼
user3859852    5 年前

如果脚本是嵌入资源( How to read embedded resource text file ,可以将其读取为字符串并使用python.exe的-c参数。