[英]Execute embedded python file from c#
我在C#中使用Python和GUI編寫了我的腳本。 這就是為什么我想從C#運行Python(我必須使用原始的Python版本,因為各種模塊,即IronPython不支持)。 為了保護腳本,我將其嵌入到.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(...)在這里沒用 ,因為我不想要流(或者我?),只是路徑。
如果腳本是嵌入式資源( 如何讀取嵌入式資源文本文件 ),則可以將其讀取為字符串並使用python.exe的-c參數
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.