【发布时间】:2019-08-05 16:14:17
【问题描述】:
我的脚本是用 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(...) 在这里不会有用,因为我不想要流(或者我想要吗?),只是路径。
【问题讨论】: