如何从字符串中携带命令 [英] how to carry a command from a string
问题描述
您好,在cmd中,我可以使用/k执行由strig指定的命令,例如:
hello again, in cmd i can use /k to carry out a command specified by a strig such as:
Shell("cmd.exe /k tracert -h " & _h & " " & domain.Text & " > temp" & i + 1 & ".txt & exit", AppWinStyle.Hide, True)
有谁知道如果我想用cygwin处理此代码,应该用/k替换什么?我已经搜索了cygwin语法,到目前为止一直无法找到任何帮助,谢谢大家.一如既往.
does anyone have any idea what should /k replaced if i want to process this code with cygwin? i have searched cygwin syntax and can''t find any help for this till now, thank you people as always.
推荐答案
您可以从简单的逻辑思维中获得答案.如果使用cmd.exe
,则/k
是其命令行参数,如cmd.exe
文档中所示.与tracert
无关.但是,这没有任何意义,因为tracert
本身是命令行应用程序,因此可以使用:
You could get an answer from simple logical thinking. If you usecmd.exe
,/k
is its command line parameter, as it is shown incmd.exe
documentation. It has nothing to do withtracert
. However, it does not make sense, becausetracert
is itself a command-line application, so you could use:
Shell("tracert -h " & _h & " " & domain.Text & " > temp" & i + 1 & ".txt & exit", AppWinStyle.Hide, True)
与sygwin
相同:
Same thing with sygwin
:
Shell("sygwin..." ...)
在这种情况下,参数"/k"不应存在.
In this case, the parameter "/k" should not be there.
嘿,我使用了SendKeys.Send发送给cygwin,它可以正常工作:
hey there, i have used SendKeys.Send to send to cygwin and it works properly:
Shell("C:\cygwin\bin\mintty.exe")
SendKeys.Send("tracert -h " & _h & " " & domain.Text & " > temp1.txt{ENTER}")
System.Threading.Thread.Sleep(120000)
SendKeys.Send("exit{ENTER}")
Shell("C:\ cygwin \ bin \ mintty.exe")
这将在与运行程序的目录相同的目录中打开cygwin终端.
SendKeys.Send("tracert -h"& _h&"& domain.Text&> temp1.txt {ENTER}")
这会将括号中的键盘键(字符串)作为命令发送到cygwin.
睡眠将等待2分钟(120000毫秒),直到traceroute完成,然后是最后一个退出cywin的命令.
我想发布此消息,因为有时您会停止编码一段时间以找到一个简单的小解决方案:),所以有人可能需要此代码.
谢谢大家的支持,特别是SAKryukov,您的msdn链接在另一个地方提供了帮助.
Shell("C:\cygwin\bin\mintty.exe")
this will open cygwin terminal in the same directory as the directory of the running program.
SendKeys.Send("tracert -h " & _h & " " & domain.Text & " > temp1.txt{ENTER}")
this will send the keyboard keys (string) within the parenthesis into cygwin as a command.
the sleep is to wait for 2 min (120000 ms) till the traceroute is finished, and then the last command to to exit cywin.
i wanted to post this because sometimes you stop coding for a time to find a simple small solution :) , so someone may need this.
thank you all for your support, specially SAKryukov, your msdn link helped in another place.
这篇关于如何从字符串中携带命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!