mirror of
https://github.com/winsw/winsw.git
synced 2025-12-10 18:37:28 +08:00
Add dev ps command
This commit is contained in:
@@ -26,6 +26,7 @@ using log4net.Core;
|
||||
using log4net.Layout;
|
||||
using WinSW.Logging;
|
||||
using WinSW.Native;
|
||||
using WinSW.Util;
|
||||
using Process = System.Diagnostics.Process;
|
||||
using TimeoutException = System.ServiceProcess.TimeoutException;
|
||||
|
||||
@@ -238,6 +239,22 @@ namespace WinSW
|
||||
root.Add(refresh);
|
||||
}
|
||||
|
||||
{
|
||||
var dev = new Command("dev");
|
||||
|
||||
dev.Add(config);
|
||||
dev.Add(noElevate);
|
||||
|
||||
root.Add(dev);
|
||||
|
||||
var ps = new Command("ps")
|
||||
{
|
||||
Handler = CommandHandler.Create<string?, bool>(DevPs),
|
||||
};
|
||||
|
||||
dev.Add(ps);
|
||||
}
|
||||
|
||||
return new CommandLineBuilder(root)
|
||||
|
||||
// see UseDefaults
|
||||
@@ -774,6 +791,58 @@ namespace WinSW
|
||||
}
|
||||
}
|
||||
|
||||
void DevPs(string? pathToConfig, bool noElevate)
|
||||
{
|
||||
XmlServiceConfig config = XmlServiceConfig.Create(pathToConfig);
|
||||
|
||||
if (!elevated)
|
||||
{
|
||||
Elevate(noElevate);
|
||||
return;
|
||||
}
|
||||
|
||||
using ServiceManager scm = ServiceManager.Open();
|
||||
using Service sc = scm.OpenService(config.Id);
|
||||
|
||||
int processId = sc.ProcessId;
|
||||
if (processId >= 0)
|
||||
{
|
||||
const string Vertical = " \u2502 ";
|
||||
const string Corner = " \u2514\u2500";
|
||||
const string Cross = " \u251c\u2500";
|
||||
const string Space = " ";
|
||||
|
||||
using Process process = Process.GetProcessById(processId);
|
||||
Draw(process, string.Empty, true);
|
||||
|
||||
static void Draw(Process process, string indentation, bool isLastChild)
|
||||
{
|
||||
Console.Write(indentation);
|
||||
|
||||
if (isLastChild)
|
||||
{
|
||||
Console.Write(Corner);
|
||||
indentation += Space;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Write(Cross);
|
||||
indentation += Vertical;
|
||||
}
|
||||
|
||||
Console.WriteLine(process.Format());
|
||||
|
||||
List<Process> children = process.GetChildren();
|
||||
int count = children.Count;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
using Process child = children[i];
|
||||
Draw(child, indentation, i == count - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// [DoesNotReturn]
|
||||
static void Elevate(bool noElevate)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user