开发者

Multiple Commands to same Text File from VB

开发者 https://www.devze.com 2023-03-06 00:43 出处:网络
I have this which is exporting the SDK info to a txt file. I would also like to export the processes that are running to the same text file.

I have this which is exporting the SDK info to a txt file. I would also like to export the processes that are running to the same text file.

Dim sdkCommand As String
    sdkCommand = "C:\Windows\System32\Java.exe -version 2> C:\Users\JavaSDKInfo.txt"
    Shell("cmd.exe /c" & sdkCommand)
End Sub

If I try adding this to it, I am only able to still see the output from sdkCommand, but nothing about the tasks that are running. I am assuming I need to combine the shell statements?

  Sub Main()
    Dim sdkCommand As String
    Dim proCommand As String
    sdkCommand = "C:\Windows\System32\Java.exe -version 2> C:\Users\Desktop\JavaSDKInfo.txt"
    proCommand = "C:\Windows\System32\tasklist.exe > C:\Users\Deskt开发者_StackOverflow社区op\JavaSDKInfo.txt"
    Shell("cmd.exe /c" & sdkCommand)
    Shell("cmd.exe /c" & proCommand)
End Sub


Combining all the commands into one long one using && actually made this work and made it easier. This allowed me to add a ton more command prompt commands.

Sub Main()
Dim sdkcommand as String
'COmbine using && in command prompt
sdkCommand = "java.exe >>C:\text.txt && tasklist.exe >>C:\text.txt"
Shell("cmd.exe /c" and sdkCommand)

End Sub

0

精彩评论

暂无评论...
验证码 换一张
取 消