如何从字符串中携带命令 [英] how to carry a command from a string

查看:94
本文介绍了如何从字符串中携带命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,在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 use cmd.exe, /k is its command line parameter, as it is shown in cmd.exe documentation. It has nothing to do with tracert. However, it does not make sense, because tracert 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"不应存在.

—SA



In this case, the parameter "/k" should not be there.

—SA


嘿,我使用了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆