Wicaledon
Wicaledon

Reputation: 810

Run PyInstaller Exe File with C#

I've written my code in Python 3.6 and got the exe file using PyInstaller. My exe needs some files to run (like txt files to read the lines). When I put the exe file and the other files in same folder, exe file works perfectly.

But when I want to run the exe file with C#, it says that it can't find the other files even they are in same folder.

As I searched on here; I used this C# code;

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);
        }
    }
}

But it didn't work. How can I fix it?

Upvotes: 1

Views: 618

Answers (1)

mjwills
mjwills

Reputation: 23820

I'd suggest setting UseShellExecute to true.

This is because setting WorkingDirectory has different behaviour depending on the value of UseShellExecute:

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.

Upvotes: 1

Related Questions