Skip to content

Commit f453656

Browse files
Working directory of fully qualified shell files was changed by mistake at #709 (#742)
(cherry picked from commit 62cd7ff)
1 parent e7da0a0 commit f453656

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

dotnet/src/dotnetframework/GxClasses.Win/Process/CommandLine.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,7 @@ public int Shell(string commandString, int modal, int redirectOutput)
129129
//If WorkingDirectory is an empty string, the current directory is understood to contain the executable.
130130
try
131131
{
132-
if (Path.IsPathRooted(file))
133-
{
134-
p.StartInfo.WorkingDirectory = Path.GetDirectoryName(file);
135-
}
136-
else
132+
if (!Path.IsPathRooted(file))
137133
{
138134
p.StartInfo.WorkingDirectory = GxContext.StaticPhysicalPath();
139135
}

dotnet/test/DotNetUnitTest/Domain/ShellTest.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,23 @@ public void WorkingDirWithSpacesTest()
3434
int errorCode = GXUtil.Shell($"'{fileName}' test", 1, 1);
3535
Assert.Equal(0, errorCode);
3636
}
37+
[Fact]
38+
public void WorkingDirForFullQualifiedBat()
39+
{
40+
string pathName = Directory.GetParent(Directory.GetCurrentDirectory()).FullName; //bat is in a different directory to the current dir
41+
string fileName = Path.Combine(pathName, "TestCurrentDir.bat");
42+
string outputFileName = Path.Combine(Directory.GetCurrentDirectory(), "output.txt"); //Current dir of the process must be the main current dir
43+
File.WriteAllText(fileName, "cd > output.txt");
44+
if (File.Exists(outputFileName))
45+
{
46+
File.Delete(outputFileName);
47+
}
48+
int errorCode = GXUtil.Shell($"{fileName}", 1, 0);
49+
string outputTxt = File.ReadAllText(outputFileName);
50+
Assert.Equal(Directory.GetCurrentDirectory(), outputTxt.Trim());
51+
Assert.Equal(0, errorCode);
52+
}
53+
3754
}
55+
3856
}

0 commit comments

Comments
 (0)