VB中的shell命令 [英] Shell commands in VB
问题描述
出于某种原因,当我尝试在 VB 的 shell 命令中使用它们时,与符号似乎无法正常工作.当我尝试使用&符号在同一行上将两个命令链接在一起时,我收到错误:filenotfoundexception was unhandled file not found"
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"
我试图运行的命令是:
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)
一切正常.vb shell 命令中没有 & 符号吗?
everything works just fine. Are ampersands not available in vb shell commands?
其实我还是有问题.所以我有的是:
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?
推荐答案
删除了我的另一个答案,找到了一个更简单的方法来做到这一点.
Deleted my other answer, found a simpler way to do this.
这就是你想要的...
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.
这篇关于VB中的shell命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!