我正在尝试将不同的内容从 .bat 文件写入文本文件。每次尝试插入一个引号 " 时,它都会避免执行此命令,嗯,看起来是因为它缺少 " 输出文件中的符号。
这是我正在尝试做的事情:
echo ' " '>> file.txt
如果我们简单地从 CLI 尝试它甚至不起作用
echo ' " '> file.txt
我在使用 MinGW 的 printf 和 echo 时遇到了同样的问题。
这里有什么问题?
最佳答案
您需要escape some special characters从字面上对待他们。特别是," double quote toggles the quote flag, if the quote flag is active, the following special characters are no longer special: ^ & | < > ( ) .
==> echo ' " '>> file.txt
' " '>> file.txt
==> type file.txt
The system cannot find the file specified.
==> echo ' ^" '>> file.txt
==> type file.txt
' " '
下一个脚本显示了 ECHO 的一些转义规则命令;如果 Delayed Expansion,请注意不同的输出(以及 caret 和 exclamation mark 的规则)被禁用或启用:
@cls
@setlocal disabledelayedexpansion
@Call :ouputOnly
@endlocal
@Echo .
@setlocal enabledelayedexpansion
@Call :ouputOnly
@endlocal
@GOTO :eof
:ouputOnly
@Echo ^@ - At Symbol: be less verbose
@Echo ^~ - Tilde: Parameter Expansion as in Call subroutines, FOR loops etc.
@Echo ^& - Single Ampersand: used as a command separator
@Echo ^&^& - Double Ampersand: conditional command separator (if errorlevel 0)
@Echo ^|^| - Double Pipe: conditional command separator (if errorlevel ^> 0)
@Echo ^:^: - Double Colon: alternative to "rem" for comments outside of code blocks
@Echo ^^ - Caret: general escape character in batch
@Echo ^" - Double Quote: surrounding a string in double quotes
@Echo escapes all of the characters contained within it
@Echo ^() - Parentheses: used to make "code blocks" of grouped commands
@Echo %% - Percentage Sign: are used to mark three of the four variable types
@Echo ^^! - Exclamation Mark: to mark delayed expansion environment variables ^^!var^^!
@Echo ^* - Asterisk: wildcard matches any number or any characters
@Echo ^? - Question Mark: matches any single character
@Echo ^. - Single dot: represents the current directory
@Echo ^.. - Double dot: represents the parent directory of the current directory
@Echo ^\ - Backslash: represent the root directory of a drive dir ^\
@Echo ^| - Single Pipe: redirects the std.output of one command
@Echo into the std.input of another
@Echo ^NUL (File like device): is like a bottomless pit
@Echo ^CON (File like device): is a file like device that represents the console
@Echo ^> - Single Greater Than: redirects output to either a file or file like device
@Echo ^>^> - Double Greater than: output will be added to the very end of the file
@Echo ^< - Less Than: redirect the contents of a file to the std.input of a command
@Echo Stream redirection: regarding the less and greater than symbols
@echo caret^^ "caret^"
@echo caret^^^^ bang^^! "caret^^ bang^!"
@exit /B
@rem based on (dead link nowadays) http://judago.webs.com/batchoperators.htm
关于windows - 缺少从 Windows 命令行或批处理中将引号“符号放入文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39232388/
我的目标是转换表单输入,例如“100兆字节”或“1GB”,并将其转换为我可以存储在数据库中的文件大小(以千字节为单位)。目前,我有这个:defquota_convert@regex=/([0-9]+)(.*)s/@sizes=%w{kilobytemegabytegigabyte}m=self.quota.match(@regex)if@sizes.include?m[2]eval("self.quota=#{m[1]}.#{m[2]}")endend这有效,但前提是输入是倍数(“gigabytes”,而不是“gigabyte”)并且由于使用了eval看起来疯狂不安全。所以,功能正常,
我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0
我想用ruby编写一个小的命令行实用程序并将其作为gem分发。我知道安装后,Guard、Sass和Thor等某些gem可以从命令行自行运行。为了让gem像二进制文件一样可用,我需要在我的gemspec中指定什么。 最佳答案 Gem::Specification.newdo|s|...s.executable='name_of_executable'...endhttp://docs.rubygems.org/read/chapter/20 关于ruby-在Ruby中编写命令行实用程序
我正在使用ruby1.9解析以下带有MacRoman字符的csv文件#encoding:ISO-8859-1#csv_parse.csvName,main-dialogue"Marceu","Giveittohimóhe,hiswife."我做了以下解析。require'csv'input_string=File.read("../csv_parse.rb").force_encoding("ISO-8859-1").encode("UTF-8")#=>"Name,main-dialogue\r\n\"Marceu\",\"Giveittohim\x97he,hiswife.\"\
我喜欢使用Textile或Markdown为我的项目编写自述文件,但是当我生成RDoc时,自述文件被解释为RDoc并且看起来非常糟糕。有没有办法让RDoc通过RedCloth或BlueCloth而不是它自己的格式化程序运行文件?它可以配置为自动检测文件后缀的格式吗?(例如README.textile通过RedCloth运行,但README.mdown通过BlueCloth运行) 最佳答案 使用YARD直接代替RDoc将允许您包含Textile或Markdown文件,只要它们的文件后缀是合理的。我经常使用类似于以下Rake任务的东西:
这似乎非常适得其反,因为太多的gem会在window上破裂。我一直在处理很多mysql和ruby-mysqlgem问题(gem本身发生段错误,一个名为UnixSocket的类显然在Windows机器上不能正常工作,等等)。我只是在浪费时间吗?我应该转向不同的脚本语言吗? 最佳答案 我在Windows上使用Ruby的经验很少,但是当我开始使用Ruby时,我是在Windows上,我的总体印象是它不是Windows原生系统。因此,在主要使用Windows多年之后,开始使用Ruby促使我切换回原来的系统Unix,这次是Linux。Rub
之前在培训新生的时候,windows环境下配置opencv环境一直教的都是网上主流的vsstudio配置属性表,但是这个似乎对新生来说难度略高(虽然个人觉得完全是他们自己的问题),加之暑假之后对cmake实在是爱不释手,且这样配置确实十分简单(其实都不需要配置),故斗胆妄言vscode下配置CV之法。其实极为简单,图比较多所以很长。如果你看此文还配不好,你应该思考一下是不是自己的问题。闲话少说,直接开始。0.CMkae简介有的人到大二了都不知道cmake是什么,我不说是谁。CMake是一个开源免费并且跨平台的构建工具,可以用简单的语句来描述所有平台的编译过程。它能够根据当前所在平台输出对应的m
我从Ubuntu服务器上的RVM转移到rbenv。当我使用RVM时,使用bundle没有问题。转移到rbenv后,我在Jenkins的执行shell中收到“找不到命令”错误。我内爆并删除了RVM,并从~/.bashrc'中删除了所有与RVM相关的行。使用后我仍然收到此错误:rvmimploderm~/.rvm-rfrm~/.rvmrcgeminstallbundlerecho'exportPATH="$HOME/.rbenv/bin:$PATH"'>>~/.bashrcecho'eval"$(rbenvinit-)"'>>~/.bashrc.~/.bashrcrbenvversions
深度学习部署:Windows安装pycocotools报错解决方法1.pycocotools库的简介2.pycocotools安装的坑3.解决办法更多Ai资讯:公主号AiCharm本系列是作者在跑一些深度学习实例时,遇到的各种各样的问题及解决办法,希望能够帮助到大家。ERROR:Commanderroredoutwithexitstatus1:'D:\Anaconda3\python.exe'-u-c'importsys,setuptools,tokenize;sys.argv[0]='"'"'C:\\Users\\46653\\AppData\\Local\\Temp\\pip-instal
有没有一种简单的方法可以将给定的整数格式化为具有固定长度和前导零的字符串?#convertnumberstostringsoffixedlength3[1,12,123,1234].map{|e|???}=>["001","012","123","234"]我找到了解决方案,但也许还有更聪明的方法。format('%03d',e)[-3..-1] 最佳答案 如何使用%1000而不是进行字符串操作来获取最后三位数字?[1,12,123,1234].map{|e|format('%03d',e%1000)}更新:根据theTinMan的