batch-file - 我如何必须转义此批处理代码中的引号?
问题描述
我如何必须转义此批处理代码中的引号?
我有以下代码:
echo ""powershell -Executionpolicy Bypass -Command "get-clipboard > C:\File.txt""" > C:\Helptool.cmd
此代码应生成文件“Helptool.cmd”。内容应如下所示:
powershell -Executionpolicy Bypass -Command "get-clipboard > C:\File.txt
我必须在哪里将 ^ 字符放在第一个批处理代码中?
当我运行上述代码时,新创建的批处理文件的内容错误如下:
"" powershell -Executionpolicy Bypass -Command "get-clipboard> C: \ File.txt" ""
开头的两个引号和结尾的三个引号是不可取的。我会通过逃跑摆脱他们。或者?我该怎么做呢?
解决方案
^
如果您对整个 PowerShell 进行双引号,则不需要任何插入符号-Command
:
这个版本使用反斜杠来转义嵌套的双引号:
@Echo @"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -Command "Get-Clipboard -Format Text -Raw -TextFormatType UnicodeText > \"C:\File.txt\"" > "C:\Helptool.cmd"
如果您更喜欢在 PowerShell 中使用单引号,则无需转义:
@Echo @"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -Command "Get-Clipboard -Format Text -Raw -TextFormatType UnicodeText > 'C:\File.txt'" > "C:\Helptool.cmd"
请注意,我已删除您的-ExecutionPolicy
参数,因为运行 s 不需要它-Command
(仅 PowerShell -File
s)。可执行文件的完整路径和扩展名powershell
是可选的,但建议与-NoProfile
参数一样。您应该打开一个 Windows PowerShell 窗口,并从 中读取输出Get-Help Get-Clipboard -Full
,以了解-Format
、Raw
和-TextFormatType
参数的作用。
推荐阅读
- python-3.x - 使用请求库切换代理代码
- python - Python从数据框创建字典
- python - tf.keras.BatchNormalization 给出意外的输出
- ajax - 提交表单时出现 500 服务器错误但未找到日志
- node.js - 如何将 json 文件中的 json 数据推送到具有新集的数组中并更新文件
- apache-kafka - UnixTime保存为int,如何查询为Date。卡桑德拉 CQLSH
- java - 让其他应用程序(文件查看器)从我们的应用程序中打开加密文件
- java - 如何从组中选中的单选按钮获取文本
- javascript - AddCircleIcon 材质 ui 禁用不工作
- javascript - 反应错误警告:render():渲染组件