-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
61 lines (51 loc) · 1.73 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
using System.Diagnostics;
using System.ComponentModel;
using System.Xml.Linq;
using System.Windows.Forms;
namespace StartNode
{
class Program
{
static void Main(string[] args)
{
string environment, nodePath, appPath, appStart;
try
{
XElement config = XElement.Load(@"config.xml");
environment = config.Element("mode").Value;
nodePath = config.Element("nodepath").Value;
appPath = config.Element("apppath").Value;
appStart = config.Element("appstart").Value;
appPath += @"\" + appStart;
Launch(environment, nodePath, appPath );
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString(), "Configuration Error", MessageBoxButtons.OK);
}
}
static void Launch(string env, string nodepath, string apppath)
{
var startInfo = new ProcessStartInfo();
startInfo.FileName = nodepath;
startInfo.Arguments = apppath;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = false;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
if(env.Length > 0)
startInfo.EnvironmentVariables.Add("NODE_ENV", env);
try
{
using (Process p = Process.Start(startInfo))
{
p.WaitForExit();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString(), "Start Error", MessageBoxButtons.OK);
}
}
}
}