Skip to content

Commit 6cfb586

Browse files
committed
commands custom OK
1 parent ef40806 commit 6cfb586

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

Fonlow.Testing.ServiceCore/Fonlow.Testing.ServiceCore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<PackageTags>xunit nunit mstest unittesting iisexpress iis dotnet</PackageTags>
1212
<NeutralLanguage>en</NeutralLanguage>
1313
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
14-
<Version>3.4</Version>
14+
<Version>3.5</Version>
1515
<PackageReadmeFile>README.md</PackageReadmeFile>
1616
<AnalysisLevel>latest-all</AnalysisLevel>
1717
</PropertyGroup>

Fonlow.Testing.ServiceCore/ServiceCommandAgent.cs

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Diagnostics;
33

44
namespace Fonlow.Testing
5-
{
5+
{
66
/// <summary>
77
/// For starting and stoping service
88
/// </summary>
@@ -13,17 +13,34 @@ public ServiceCommandAgent(ServiceCommand serviceCommand)
1313
this.ServicCommand = serviceCommand;
1414
}
1515

16-
public ServiceCommand ServicCommand { get; private set; }
17-
16+
public ServiceCommand ServicCommand { get; private set; }
17+
1818
/// <summary>
1919
/// Start DotNet Kestrel Web server.
2020
/// </summary>
2121
public void Start()
22-
{
23-
ProcessStartInfo info = new ProcessStartInfo(ServicCommand.CommandPath, ServicCommand.Arguments)
24-
{
25-
UseShellExecute = true,
26-
};
22+
{
23+
ProcessStartInfo info;
24+
var dir = System.IO.Path.GetDirectoryName(ServicCommand.CommandPath);
25+
if (string.IsNullOrEmpty(dir))
26+
{
27+
info = new ProcessStartInfo(ServicCommand.CommandPath, ServicCommand.Arguments)
28+
{
29+
UseShellExecute = true,
30+
};
31+
}
32+
else
33+
{
34+
string command = System.IO.Path.GetFileName(ServicCommand.CommandPath);
35+
string workingDir = System.IO.Path.GetFullPath(dir);
36+
info = new ProcessStartInfo(command, ServicCommand.Arguments)
37+
{
38+
UseShellExecute = true,
39+
WorkingDirectory = workingDir
40+
};
41+
42+
Console.WriteLine($"Working Dir: {workingDir}; Current Dir: {System.IO.Directory.GetCurrentDirectory()}");
43+
}
2744

2845
Console.WriteLine($"Starting {ServicCommand.CommandPath} {ServicCommand.Arguments} ...");
2946
process = Process.Start(info);
@@ -36,8 +53,8 @@ public void Start()
3653

3754
DateTime timeStart;
3855

39-
Process process;
40-
56+
Process process;
57+
4158
/// <summary>
4259
/// Stop service launched by this agent.
4360
/// </summary>
@@ -51,9 +68,9 @@ public void Stop()
5168
}
5269

5370
try
54-
{
55-
//sometimes the process exited before the kill. Then the kill may leave a ghost terminal screen. This seems to be the new behavior in Windows 11.
56-
// This typically happens when the Web service was launched manually, then run the test suite which will lauch the same service using this agent class.
71+
{
72+
//sometimes the process exited before the kill. Then the kill may leave a ghost terminal screen. This seems to be the new behavior in Windows 11.
73+
// This typically happens when the Web service was launched manually, then run the test suite which will lauch the same service using this agent class.
5774
if (!process.HasExited)
5875
{
5976
process.Kill(true);

0 commit comments

Comments
 (0)