如何在Linux上用C#启动服务
我想通过Mono在我的Linux服务器上使用C#控制台应用程序启动一项服务如何在Linux上用C#启动服务,c#,linux,mono,C#,Linux,Mono,我想通过Mono在我的Linux服务器上使用C#控制台应用程序启动一项服务 public static void StartService(string serviceName, int timeoutMilliseconds) { ServiceController service = new ServiceController(serviceName); try { TimeSpan timeout = TimeSpan.FromMilliseconds(timeoutM
public static void StartService(string serviceName, int timeoutMilliseconds)
{
ServiceController service = new ServiceController(serviceName);
try
{
TimeSpan timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds);
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running, timeout);
}
catch
{
// ...
}
}
这样行吗
另外,有没有一种方法可以像在Windows系统上发送命令一样,通过C#向Linux发送命令
我正在尝试使用C可执行文件启动Linux服务。您可以通过这样做来执行命令
Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "/bin/bash";
proc.StartInfo.Arguments = "-c 'your command here'";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.Start();
和可能的副本