0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

コマンド実行結果取得

Last updated at Posted at 2025-04-27

コマンド実行結果取得

指定したコマンドを実行し、実行結果を取得する。
DoEventsによる待ちは作成ツールにおいて基本デメリットにしかならないため実施しない。

コマンド実行結果取得

'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' コマンド実行結果取得
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' コマンド実行結果取得
'------------------------------------------------------------------------------
Public Function F_Cmd_GetCommandResult( _
        ByRef aRtn As String, _
        ByVal aCmd As String) As Boolean
    Dim wkRtn As String
    
    '引数チェック
    If aCmd = "" Then
        Exit Function
    End If
    
    F_Cmd_GetCommandResult = M_Shell.F_Shell_GetResult(aRtn, "%ComSpec% /c " & aCmd)
End Function

コマンド実行結果配列取得

'------------------------------------------------------------------------------
' コマンド実行結果配列取得
'------------------------------------------------------------------------------
Public Function F_Cmd_GetCommandResultArray( _
        ByRef aRtnAry As Variant, _
        ByVal aCmd As String) As Boolean
    Dim wkRtnAry As Variant
    Dim wkRtnStr As String
    
    Dim wkTmpAry As Variant, wkTmp As Variant
    Dim wkTmpAry2 As Variant, wkTmp2 As Variant
    
    'コマンドの結果がNGであれば終了
    If F_Cmd_GetCommandResult(wkRtnStr, aCmd) <> True Then
        Exit Function
    End If
    
    'CRLF区切りで分割
    If M_String.F_String_GetSplit(wkTmpAry, wkRtnStr, vbCrLf) = True Then
        For Each wkTmp In wkTmpAry
            '空行でなければ追加
            If wkTmp <> "" Then
                wkRtnAry = M_Common.F_ReturnArrayAdd(wkRtnAry, wkTmp)
            End If
        Next wkTmp
    End If
    
    If IsArray(wkRtnAry) = True Then
        aRtnAry = wkRtnAry
        F_Cmd_GetCommandResultArray = True
    End If
End Function
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?