Shell commands in VB

前端 未结 3 1236
伪装坚强ぢ
伪装坚强ぢ 2021-01-23 05:15

For some reason it seems that ampersands are not working like they should when I attempt to use them in shell commands in VB. When I attempt to link two commands together on the

相关标签:
3条回答
  • 2021-01-23 05:44

    Have you considered using the Process object to start ADB with the CommandLine options being set

    Dim psi As New ProcessStartInfo
    
    psi.WorkingDirectory = "c:\"
    psi.Arguments = "shell monkey -p com.android.system -v 1"
    psi.FileName = "ADB"
    psi.WindowStyle = ProcessWindowStyle.Hidden
    return Process.Start(psi)
    

    in the event that your ADB program only allows a single instance to run, maybe you need to add the following

    Dim ps As Process = Process.Start(psi)
    ps.WaitForExit()
    
    psi.Arguments = 'new arguments
    Process.Start(psi)
    
    0 讨论(0)
  • 2021-01-23 05:51

    The Shell command expects a file name, so command line extensions won't work.

    There are a couple of options:

    1) Start cmd.exe with process.start and pass the parameters (I have not tested this, so am unsure if it will work.

    2) Create your commands in a .cmd or .bat file and then shell that file (this seems like it might be the easiest approach).

    0 讨论(0)
  • 2021-01-23 05:58

    Deleted my other answer, found a simpler way to do this.

    This is what you want...

    Shell("cmd.exe /c cd C:\ & adb shell monkey -p com.android.system -v 1", AppWinStyle.Hide)
    

    Inserting it into your original code...

    Shell("cmd.exe /c cd " & TextBox2.Text.ToString & " & adb -s " & TextBox15.Text.ToString & " shell monkey -p " & TextBox1.Text.ToString & " -v 1", AppWinStyle.Hide) 
    

    I tested the first example and it seemed to work.

    0 讨论(0)
提交回复
热议问题