1

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?

mjwills
  • 23,389
  • 6
  • 40
  • 63
Wicaledon
  • 710
  • 1
  • 11
  • 26
  • @mjwills They are in `"C:\Users\wicaledon\OneDrive\Desktop\Test\"` folder. It doesn't work if I comment out `CreateNoWindow` line. This is .NET Core. – Wicaledon Aug 20 '19 at 11:58

1 Answers1

1

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.

mjwills
  • 23,389
  • 6
  • 40
  • 63
  • I have a question to you. I used these lines and it works on Windows10 perfectly. But there is problem in Windows7. Should we change some lines? Or the problem is from mine somewhere? – Wicaledon Aug 24 '19 at 21:58