Skip to content

Commit

Permalink
Working directory of fully qualified shell files was changed by mista…
Browse files Browse the repository at this point in the history
…ke at #709 (#742)

(cherry picked from commit 62cd7ff)
  • Loading branch information
claudiamurialdo committed Feb 3, 2023
1 parent e7da0a0 commit f453656
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,7 @@ public int Shell(string commandString, int modal, int redirectOutput)
//If WorkingDirectory is an empty string, the current directory is understood to contain the executable.
try
{
if (Path.IsPathRooted(file))
{
p.StartInfo.WorkingDirectory = Path.GetDirectoryName(file);
}
else
if (!Path.IsPathRooted(file))
{
p.StartInfo.WorkingDirectory = GxContext.StaticPhysicalPath();
}
Expand Down
18 changes: 18 additions & 0 deletions dotnet/test/DotNetUnitTest/Domain/ShellTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,23 @@ public void WorkingDirWithSpacesTest()
int errorCode = GXUtil.Shell($"'{fileName}' test", 1, 1);
Assert.Equal(0, errorCode);
}
[Fact]
public void WorkingDirForFullQualifiedBat()
{
string pathName = Directory.GetParent(Directory.GetCurrentDirectory()).FullName; //bat is in a different directory to the current dir
string fileName = Path.Combine(pathName, "TestCurrentDir.bat");
string outputFileName = Path.Combine(Directory.GetCurrentDirectory(), "output.txt"); //Current dir of the process must be the main current dir
File.WriteAllText(fileName, "cd > output.txt");
if (File.Exists(outputFileName))
{
File.Delete(outputFileName);
}
int errorCode = GXUtil.Shell($"{fileName}", 1, 0);
string outputTxt = File.ReadAllText(outputFileName);
Assert.Equal(Directory.GetCurrentDirectory(), outputTxt.Trim());
Assert.Equal(0, errorCode);
}

}

}

0 comments on commit f453656

Please sign in to comment.