Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shell commands in VB

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 same line using an ampersand i receive the error: "filenotfoundexception was unhandled file not found"

The command I am trying to run is:

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

I tried breaking it down to a more simplistic form, but im still receiving the error:

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

If I get rid of the ampersand and just use:

 shell(adb shell monkey -p com.android.system -v 1", AppWinStyle.Hide)

everything works just fine. Are ampersands not available in vb shell commands?


*My edit

Actually I am still having trouble. So what i have is:

    psi.WorkingDirectory = TextBox2.Text.ToString
    psi.FileName = "adb"
    psi.WindowStyle = ProcessWindowStyle.Hidden

then I have a little bit of code, and then I assign an argument and execute the argument:

    psi.Arguments = "-s " & TextBox15.Text.ToString & " shell monkey -p " & TextBox1.Text.ToString & " -v  1"
    Process.Start(psi)

then I have a little bit of code, and then I try running the process again with a different argument:

    psi.Arguments = "-s " & TextBox15.Text.ToString & " shell input keyevent 3"
    Process.Start(psi)

First one seems to work, all the subsequent ones do not. Is there any reason why this shouldnt work? is there a process refresh or something that I am missing?

like image 416
Nefariis Avatar asked Feb 28 '26 18:02

Nefariis


1 Answers

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.

like image 138
JohnFx Avatar answered Mar 03 '26 10:03

JohnFx



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!