piotrwest
piotrwest

Reputation: 2166

System.Diagnostics.Process.Start() opens/runs wrong directory?

I think I found a bug. In my opinion Process.Start runs wrong directory. To test, create default console application template and paste following:


using System;
using System.Diagnostics;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            bool test = false;

            DirectoryInfo root = Directory.CreateDirectory(
                System.IO.Path.Combine(Directory.GetCurrentDirectory(), "folder"));

            DirectoryInfo bug = Directory.CreateDirectory(
                System.IO.Path.Combine(root.FullName, "bug"));
            DirectoryInfo bugDotCom = Directory.CreateDirectory(
                System.IO.Path.Combine(root.FullName, "bug.com"));

            ProcessStartInfo bugPSI = new ProcessStartInfo(bug.FullName);
            ProcessStartInfo bugDotComPSI = new ProcessStartInfo(bugDotCom.FullName);

            if (test)
            {
                Console.WriteLine(bug.FullName);
                Process.Start(bugPSI);
            }
            else
            {
                Console.WriteLine(bugDotCom.FullName);
                Process.Start(bugDotComPSI);
            }
            Console.ReadKey();
        }
    }
}

when variable test is set to false, bug.com directory should be opened, otherwise bug directory. However, this example shows that always bug.com is opened (no matter to test variable) - at least for me. What's wrong? I'm missing something or that's just a bug?

Upvotes: 1

Views: 1088

Answers (1)

SLaks
SLaks

Reputation: 887413

.com is part of %PATHEXT%, so Windows will use it if it exists.

Changing the extension so that there is no bug.com folder avoids the problem.

To fix the problem, add a \ to the end of the path.

Upvotes: 2

Related Questions