运行 使用 C# 的 PyInstaller 可执行文件
Run PyInstaller Exe File with C#
我在 Python 3.6 中编写了我的代码,并使用 PyInstaller 获取了 exe 文件。我的 exe 需要一些文件到 运行(比如 txt 文件来读取行)。当我将 exe 文件和其他文件放在同一个文件夹中时,exe 文件完美运行。
但是当我想用 C# 运行 exe 文件时,它说即使它们在同一文件夹中也找不到其他文件。
正如我在 上搜索的那样;我使用了这个 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);
}
}
}
但是没有用。我该如何解决?
我建议将 UseShellExecute
设置为 true
。
这是因为设置WorkingDirectory
根据UseShellExecute
的值有不同的behaviour:
When the UseShellExecute property is false, gets or sets the working
directory for the process to be started. When UseShellExecute is true,
gets or sets the directory that contains the process to be started.
我在 Python 3.6 中编写了我的代码,并使用 PyInstaller 获取了 exe 文件。我的 exe 需要一些文件到 运行(比如 txt 文件来读取行)。当我将 exe 文件和其他文件放在同一个文件夹中时,exe 文件完美运行。
但是当我想用 C# 运行 exe 文件时,它说即使它们在同一文件夹中也找不到其他文件。
正如我在
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);
}
}
}
但是没有用。我该如何解决?
我建议将 UseShellExecute
设置为 true
。
这是因为设置WorkingDirectory
根据UseShellExecute
的值有不同的behaviour:
When the UseShellExecute property is false, gets or sets the working directory for the process to be started. When UseShellExecute is true, gets or sets the directory that contains the process to be started.