1 | #Region "Microsoft.VisualBasic::81e48996fb61793a1a5ea21ab69f3f0b, Microsoft.VisualBasic.Core\Language\Language\UnixBash\LinuxRunHelper.vb" |
2 | |
3 | ' Author: |
4 | ' |
5 | ' asuka (amethyst.asuka@gcmodeller.org) |
6 | ' xie (genetics@smrucc.org) |
7 | ' xieguigang (xie.guigang@live.com) |
8 | ' |
9 | ' Copyright (c) 2018 GPL3 Licensed |
10 | ' |
11 | ' |
12 | ' GNU GENERAL PUBLIC LICENSE (GPL3) |
13 | ' |
14 | ' |
15 | ' This program is free software: you can redistribute it and/or modify |
16 | ' it under the terms of the GNU General Public License as published by |
17 | ' the Free Software Foundation, either version 3 of the License, or |
18 | ' (at your option) any later version. |
19 | ' |
20 | ' This program is distributed in the hope that it will be useful, |
21 | ' but WITHOUT ANY WARRANTY; without even the implied warranty of |
22 | ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23 | ' GNU General Public License for more details. |
24 | ' |
25 | ' You should have received a copy of the GNU General Public License |
26 | ' along with this program. If not, see <http://www.gnu.org/licenses/>. |
27 | |
28 | |
29 | |
30 | ' /********************************************************************************/ |
31 | |
32 | ' Summaries: |
33 | |
34 | ' Module LinuxRunHelper |
35 | ' |
36 | ' Function: BashRun, BashShell, MonoRun, PerlShell, ScriptMe |
37 | ' |
38 | ' |
39 | ' /********************************************************************************/ |
40 | |
41 | #End Region |
42 | |
43 | Imports System.Reflection |
44 | Imports System.Text |
45 | Imports Microsoft.VisualBasic.ApplicationServices |
46 | Imports Microsoft.VisualBasic.CommandLine |
47 | |
48 | Namespace Language.UnixBash |
49 | |
50 | ''' <summary> |
51 | ''' mono shortcuts |
52 | ''' </summary> |
53 | Public Module LinuxRunHelper |
54 | |
55 | ''' <summary> |
56 | ''' perl ./<see cref="Assembly"/> @ARGV |
57 | ''' </summary> |
58 | ''' <returns></returns> |
59 | Public Function ScriptMe() As String |
60 | Dim cmd As String = Assembly.GetEntryAssembly.Location |
61 | Dim perl As String = |
62 | $"#!/usr/bin/perl |
63 | |
64 | use strict; |
65 | use warnings; |
66 | use File::Basename; |
67 | use File::Spec; |
68 | |
69 | my $cli = join "" "", @ARGV; |
70 | |
71 | print ""{App.AssemblyName} << $cli\n""; |
72 | system(""mono {cmd.CLIPath} $cli""); |
73 | " |
74 | Return perl |
75 | End Function |
76 | |
77 | ''' <summary> |
78 | ''' Run from bash shell |
79 | ''' </summary> |
80 | ''' <returns></returns> |
81 | Public Function BashRun() As String |
82 | Dim cmd As String = Assembly.GetEntryAssembly.Location |
83 | Dim bash As String = |
84 | $"#!/bin/sh |
85 | |
86 | cli=""$@""; |
87 | |
88 | echo ""{App.AssemblyName} <<< $@""; |
89 | mono ""{cmd}"" $cli |
90 | " |
91 | Return bash.Replace(vbCr, "") |
92 | End Function |
93 | |
94 | ''' <summary> |
95 | ''' 这里比perl脚本掉调用有一个缺点,在运行前还需要使用命令修改为可执行权限 |
96 | ''' 'sudo chmod 777 cmd.sh' |
97 | ''' </summary> |
98 | ''' <returns></returns> |
99 | Public Function BashShell() As Integer |
100 | Dim path As String = Assembly.GetEntryAssembly.Location.TrimSuffix |
101 | Return BashRun.SaveTo(path, Encoding.ASCII) |
102 | End Function |
103 | |
104 | ''' <summary> |
105 | ''' Execute command using perl script |
106 | ''' </summary> |
107 | ''' <returns></returns> |
108 | Public Function PerlShell() As Integer |
109 | Dim path As String = Assembly.GetEntryAssembly.Location.TrimSuffix & ".pl" |
110 | Return ScriptMe.SaveTo(path) |
111 | End Function |
112 | |
113 | Public Function MonoRun(app As String, CLI As String) As ProcessEx |
114 | Dim proc As New ProcessEx With { |
115 | .Bin = "mono", |
116 | .CLIArguments = app.GetFullPath.CLIPath & " " & CLI |
117 | } |
118 | Return proc |
119 | End Function |
120 | End Module |
121 | End Namespace |