microsoft-visualbasic-runtime/My/LinuxRunHelper.vb

100 lines
3.1 KiB
VB.net
Raw Normal View History

2019-07-29 02:05:05 +08:00
#Region "Microsoft.VisualBasic::b3a106c39670fb151d62b3b32d984b29, Microsoft.VisualBasic.Core\My\LinuxRunHelper.vb"
2018-08-02 20:14:48 +08:00
2019-07-17 22:01:31 +08:00
' Author:
'
' asuka (amethyst.asuka@gcmodeller.org)
' xie (genetics@smrucc.org)
' xieguigang (xie.guigang@live.com)
'
' Copyright (c) 2018 GPL3 Licensed
'
'
' GNU GENERAL PUBLIC LICENSE (GPL3)
'
'
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program. If not, see <http://www.gnu.org/licenses/>.
2018-08-02 20:14:48 +08:00
2019-07-17 22:01:31 +08:00
' /********************************************************************************/
2018-08-02 20:14:48 +08:00
2019-07-17 22:01:31 +08:00
' Summaries:
2018-08-02 20:14:48 +08:00
2019-07-17 22:01:31 +08:00
' Module LinuxRunHelper
'
' Function: BashRun, BashShell, MonoRun
'
'
' /********************************************************************************/
2018-08-02 20:14:48 +08:00
#End Region
Imports Microsoft.VisualBasic.ApplicationServices
Imports Microsoft.VisualBasic.CommandLine
Imports Microsoft.VisualBasic.Text
2018-08-02 20:14:48 +08:00
2019-07-17 21:33:09 +08:00
Namespace My
2018-08-02 20:14:48 +08:00
''' <summary>
''' mono shortcuts
''' </summary>
Public Module LinuxRunHelper
''' <summary>
''' Run from bash shell
''' </summary>
''' <returns></returns>
Public Function BashRun() As String
Dim appName = App.AssemblyName
Dim bash As String = Encodings.UTF8WithoutBOM _
.CodePage _
.GetString(My.Resources.bashRunner) _
.Replace("{appName}", appName) _
.LineTokens _
.JoinBy(ASCII.LF)
2018-08-02 20:14:48 +08:00
Return bash
2018-08-02 20:14:48 +08:00
End Function
''' <summary>
''' 这里比perl脚本掉调用有一个缺点在运行前还需要使用命令修改为可执行权限
'''
''' ```
2018-08-02 20:14:48 +08:00
''' 'sudo chmod 777 cmd.sh'
''' ```
2018-08-02 20:14:48 +08:00
''' </summary>
''' <returns></returns>
Public Function BashShell() As Integer
Dim path As String = App.ExecutablePath.TrimSuffix
Dim bash As String = BashRun()
' 在这里写入的bash脚本都是没有文件拓展名的
'
' 同时写入man命令帮助脚本
Call My.Resources.help.FlushStream(path.ParentPath & "/help")
Call BashRun.SaveTo(path, Encodings.UTF8WithoutBOM.CodePage)
Return 0
2018-08-02 20:14:48 +08:00
End Function
Public Function MonoRun(app As String, CLI As String) As ProcessEx
Dim proc As New ProcessEx With {
.Bin = "mono",
.CLIArguments = app.GetFullPath.CLIPath & " " & CLI
}
Return proc
End Function
End Module
End Namespace