简体   繁体   English

在Windows命令行中无法正确识别“ \\ n”

[英]“\n” is not being recognized properly in Windows command line

I'm trying to issue a command that requires a line break due to a formatting restriction. 我正在尝试发出由于格式限制而需要换行的命令。

I need to commit a file to a CVS repository, but the repository has a restriction that requires a message to be included in the following format. 我需要将文件提交到CVS存储库,但是存储库有一个限制,要求以以下格式包含一条消息。

Change #: <number>
Description: <description>

The command used to commit the file is: 用于提交文件的命令是:

cvs commit -m "Change #: <number>\nDescription: <description>" <filename>

However when I issue the command it doesn't seem to be properly recognizing the line break and it fails saying that I gave it an invalid Change # and no Description. 但是,当我发出命令时,它似乎无法正确识别换行符,并且无法说我给它提供了无效的Change#和No Description。

How can I make it recognize the new line without it trying to issue two separate commands? 如何在不尝试发出两个单独命令的情况下使其识别新行?

Try powershell in this format: 尝试使用以下格式的powershell:

start-process -FilePath cvs.exe -ArgumentList "commit -m `"Change #:123 `nDescription:my description`""

I'm actually attempting to call this command from a Perl script and found an acceptable workaround. 我实际上正在尝试从Perl脚本调用此命令,并找到了可接受的解决方法。 For some reason calling the command as a system command seems to fail, but if you call it using backticks it works fine. 由于某种原因,将该命令作为system命令调用似乎失败,但是如果使用反引号调用它,则可以正常运行。

# Fails
system 'cvs commit -m "Change #: <number>\nDescription: <description>" <filename>'

# Works
my $output = `cvs commit -m "Change #: <number>\nDescription: <description>" <filename>`

Whats funny is this difference in handling "\\n" between using system commands and backticks doesn't seem to be documented anywhere. 有趣的是,使用system命令和反引号之间在处理“ \\ n”方面的区别似乎没有任何地方记录在案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM