问题描述
我正在尝试从 windows servie 项目中的 OnStart 方法启动一个 jar 文件作为进程,但 java 进程无法启动
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
namespace TestJarasAService
{
public partial class Imaging_Sync_Test : ServiceBase
{
public Imaging_Sync_test()
{
InitializeComponent();
if (!System.Diagnostics.EventLog.sourceExists("ImageSyncService"))
System.Diagnostics.EventLog.CreateEventSource("ImageSyncService","ImageSyncServiceLog");
eventLog1.source = "ImageSyncService";
eventLog1.Log = "ImageSyncServiceLog";
}
protected override void OnStart(string[] args)
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.processstartinfo startInfo = new System.Diagnostics.processstartinfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "java -jar SyncServiceTest-0.0.1-SNAPSHOT.jar";
process.StartInfo = startInfo;
process.Start();
}
protected override void OnStop()
{
//eventLog1.WriteEntry(process.Id.ToString());
//process.Kill();
eventLog1.WriteEntry("my service stoped");
}
protected override void OnContinue()
{
eventLog1.WriteEntry("my service is continuing in working");
}
private void eventLog1_EntryWritten(object sender,EntryWrittenEventArgs e)
{
}
}
}
如果我在启动 Jar 文件时遗漏了一些东西,有人可以帮忙。相同的命令适用于 Windows 命令外壳
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)