Shell命令中的双引号 [英] Double quotes within the Shell command

查看:166
本文介绍了Shell命令中的双引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我正在尝试在Visual Basic中运行批处理文件代码.有人告诉我可以使用Shell命令执行此操作,但是双引号会给我带来麻烦.

I'm trying to run batch files code within Visual Basic.  I've been told you can do this using the Shell command, however I'm running into trouble with double quotes.

由于Shell命令语法为Shell("codecodecode"),所以我不确定在批处理文件已包含引号的情况下该怎么做.

As the Shell command syntax is Shell("codecodecode"), I'm not sure what to do when the batch file already contains quotes.

例如,我将如何使用代码:

For example, how would I use the code:

复制文件位置" 目的地"

copy "file location" "destination"

在外壳内?

谢谢

推荐答案

在字符串文字中,使用双引号两次,例如

Within a string literal, use the double quotes twice, e.g.

   将dim作为字符串

   dim s as string

  s =他键入了",这是文本".进入他的键盘."

   s = "He typed ""this is a text"" into his keyboard."


但是,不能将命令解释器的内部命令与shell函数一起使用.你得写


However, you can not use internal commands of the command interpreter with the shell function. You'd have to write

    shell("cmd/c复制"文件位置"目标)

   shell("cmd /c copy ""file location"" ""destination""")

但是正如您所写的,这只是一个例子,我认为这不是您的意图.首先是因为有IO.File.Copy.

But as you wrote it's an example, I think this wasn't your intention. Above all because there's IO.File.Copy.

顺便说一句,还有一个Process.Start函数来启动一个进程.

BTW, there's also the Process.Start function to start a process.


这篇关于Shell命令中的双引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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