-
Notifications
You must be signed in to change notification settings - Fork 4
/
Java.vb
33 lines (28 loc) · 1.17 KB
/
Java.vb
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
Imports System.ComponentModel
Namespace ProcessManagement
Public Class Java
Inherits ConsoleApp
Public Sub New(jarFilename As String, arguments As String, Optional captureConsoleOutput As Boolean = True, Optional captureConsoleError As Boolean = True)
MyBase.New("java",
$"-jar ""{jarFilename}""" &
If( 'If arguments are present, add a space before them; otherwise, don't
Not String.IsNullOrEmpty(arguments),
$" ""{arguments}""",
""),
captureConsoleOutput, captureConsoleError
)
End Sub
Protected Overrides Sub Start()
Try
MyBase.Start()
Catch ex As Win32Exception
If ex.NativeErrorCode = 2 Then
'2 means "file not found". Additional reading: https://msdn.microsoft.com/en-us/library/cc231199.aspx
Throw New JavaNotFoundException(ex)
Else
Throw
End If
End Try
End Sub
End Class
End Namespace