【问题标题】:Run PyInstaller Exe File with C#使用 C# 运行 PyInstaller Exe 文件
【发布时间】:2019-12-25 14:57:41
【问题描述】:

我在 Python 3.6 中编写了我的代码,并使用 PyInstaller 获取了 exe 文件。我的 exe 需要一些文件才能运行(比如 txt 文件来读取行)。当我将 exe 文件和其他文件放在同一个文件夹中时,exe 文件可以正常工作。

但是当我想用 C# 运行 exe 文件时,它说即使它们在同一个文件夹中也找不到其他文件。

正如我在here 上搜索的;我使用了这个 C# 代码;

using System.Diagnostics;
using System.IO;

namespace RunExeFile
{
    class Program
    {
        static void Main(string[] args)
        {
            ProcessStartInfo _processStartInfo = new ProcessStartInfo();
            _processStartInfo.WorkingDirectory = "C:\\Users\\wicaledon\\OneDrive\\Desktop\\Test\\";
            _processStartInfo.FileName = @"Statistics.exe";
            _processStartInfo.CreateNoWindow = true;
            Process myProcess = Process.Start(_processStartInfo);
        }
    }
}

但它没有用。我该如何解决?

【问题讨论】:

  • @mjwills 它们位于"C:\Users\wicaledon\OneDrive\Desktop\Test\" 文件夹中。如果我注释掉 CreateNoWindow 行,它将不起作用。这是 .NET Core。

标签: c# .net-core pyinstaller executable


【解决方案1】:

我建议将UseShellExecute 设置为true

这是因为设置WorkingDirectory有不同的behaviour取决于UseShellExecute的值:

当 UseShellExecute 属性为 false 时,获取或设置工作 要启动的进程的目录。当 UseShellExecute 为真时, 获取或设置包含要启动的进程的目录。

【讨论】:

  • 我有一个问题要问你。我使用了这些行,它可以在 Windows10 上完美运行。但是Windows7有问题。我们应该改变一些行吗?还是问题出在我的某个地方?
猜你喜欢
  • 2021-04-22
  • 2019-11-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-26
  • 1970-01-01
相关资源
最近更新 更多