cmd中的转义字符是哪个符号? [英] Which symbol is escape character in cmd?

查看:220
本文介绍了cmd中的转义字符是哪个符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

powershell -command "& { (New-Object Net.WebClient).DownloadFile('linkToMyFile.file', 'C:\my.file') }"

该文件可供下载

当我在远程服务器上的cmd中执行它时-一切正常。

但是当我想使用paexec在远程服务器上的计算机上执行此代码时,

我的CMD中的命令:

it's for download file.
When I execute it in cmd on remote server - everything is ok.
But when I want to execute this code from my computer on remote server using paexec, I have some troubles with escape characters.
Command in my CMD:

psexec.exe \\remoteServer.0.1 -u username -p password -dbg -lo D:\PsExec.log cmd /c "powershell -command "& { (New-Object Net.WebClient).DownloadFile('linkToMyFile.file', 'C:\my.file') }""

我尝试使用^符号,但存在相同的错误;

使用^符号的双引号代码:

I try to use ^ symbol, but the same error;
Code using ^ symbol for double-quotes:

psexec.exe \\remoteServer.0.1 -u username -p password -dbg -lo D:\PsExec.log cmd /c "powershell -command ^"& { (New-Object Net.WebClient).DownloadFile('linkToMyFile.file', 'C:\my.file') }^""

此外,我尝试使用 \ (类似于PHP)进行转义,但结果相同。

对此提供帮助或提出建议,我该如何使用命令行远程下载文件。

Also, I tried to use \ (like in PHP) for escape, but have the same result.
Help with this or give advice how I can remotely download a file using the command line.

推荐答案

不幸的是,CMD使用<一个href = http://ss64.com/nt/syntax-esc.html rel = nofollow noreferrer>不同的转义字符,具体取决于要转义的内容和位置。

Unfortunately CMD uses different escape characters depending on what is escaped and where. There is no single one escape character that would be used everywhere.

在大多数情况下,下一个字符通过在插入符前插入一个转义符来进行转义( ^ ),例如在 for / f 循环中:

In most cases the next character is escaped by prepending it with a caret (^), e.g. in for /f loops:

for /f "tokens=1" %%a in ('type file.txt ^| find "something"') do ...

但是有时通过将字符加倍来逃脱字符,例如批处理脚本中的百分比字符():

But sometimes characters are escaped by doubling them, e.g. percent characters (%) in batch scripts:

@echo off
echo %%DATE%%=%DATE%

有时您甚至可能需要放其他转义字符(例如反斜杠),因为您不需要转义某些内容,而不是CMD,但是对于命令,该字符串将传递给:

Sometimes you may even need need to put in other escape characters (like backslashes) because you need to escape something not for CMD, but for the command the string is being passed to:

mountvol | findstr /r \\\\

您的特定情况下不需要附加引号或逃避,尽管。只需直接运行PowerShell命令行,而无需 cmd / c

Your particular scenario shouldn't require additional quotes or escaping, though. Just run the PowerShell commandline directly, without cmd /c:

paexec.exe \\remoteServer.0.1 -u username -p password powershell -command "&{...}"

这篇关于cmd中的转义字符是哪个符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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