0

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.

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.

How can I make it recognize the new line without it trying to issue two separate commands?

tjwrona1992
  • 8,614
  • 8
  • 35
  • 98
  • Perhaps "\r\n" for a true Windows newline? – Corey Ogburn Jan 14 '16 at 18:27
  • I gave that a try and it didn't work either :( – tjwrona1992 Jan 14 '16 at 18:29
  • Try a carot ^ http://superuser.com/questions/150116/how-can-i-insert-a-new-line-in-a-cmd-exe-command – Corey Ogburn Jan 14 '16 at 18:30
  • That's not working either. The quotes seem to mess up the carot. – tjwrona1992 Jan 14 '16 at 18:42
  • The legacy Windows command line isn't that sophisticated. Unless `cvs` itself provides a mechanism for inserting line breaks, you'll need to use something else; Adam's suggestion of Powershell seems sound, if you don't want to use a GUI. – Harry Johnston Jan 15 '16 at 09:43
  • @tjwrona1992 - did the suggestion below work for you? – Adam Tuliper Jan 19 '16 at 18:20
  • @AdamTuliper-MSFT I actually ended up finding another workaround. I'm issuing the command from a Perl script. I was originally calling it using a Perl `system` command but that wasn't working. For some reason if you call it with backticks instead it functions correctly. Its strange because I don't see any reason for this documented anywhere. – tjwrona1992 Jan 20 '16 at 14:47

2 Answers2

1

Try powershell in this format:

start-process -FilePath cvs.exe -ArgumentList "commit -m `"Change #:123 `nDescription:my description`""
Adam Tuliper
  • 29,982
  • 4
  • 53
  • 71
  • How do you use a newline in a script? Would it solve [this problem](http://stackoverflow.com/q/34491463/886887) too? – Harry Johnston Jan 14 '16 at 23:08
  • actually.. thats an interesting post. I didn't realize the parser was broken in that sense (if its indeed been verified). I believe start-process uses createprocess, if so this should be ok, but lets see. – Adam Tuliper Jan 15 '16 at 07:43
  • Oh, you meant a Powershell script; my mistake. Probably not relevant then. – Harry Johnston Jan 15 '16 at 09:38
0

I'm actually attempting to call this command from a Perl script and found an acceptable workaround. For some reason calling the command as a system command seems to fail, but if you call it using backticks it works fine.

# 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.

tjwrona1992
  • 8,614
  • 8
  • 35
  • 98
  • [Documented here:](http://www.perlhowto.com/executing_external_commands) "If the argument [to system] is a scalar, system() uses the shell to execute the command". – Harry Johnston Jan 20 '16 at 20:34