3

I've found some execution command from Unreal Build Tool:

C:\VisualStudio\IDE2017\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64\cl.exe @"C:\MessageTag\Intermediate\Build\Win64\MessageTest\Development\DesktopPlatform\Module.DesktopPlatform.cpp.obj.response" /showIncludes

I tested a simple command line

cl @"F:\x\cc.txt"

with file content of cc.txt:

x.cpp
-Fe"y.exe"

The y.exe is created, and it seems that lines in the file "cc.txt" are chained into a string.

However if I simply type this:

@"F:\x\cc.txt"

in the command line, the text file is opened, neither showing file content nor execute the first line of the file content.

What does the "@" exactly do? Is there a documentation for it?

further question: This only works on cmd. Is there a Powerhsell equivalent?

mklement0
  • 382,024
  • 64
  • 607
  • 775
karatoga
  • 513
  • 4
  • 14
  • 1
    Possible duplicate of [What is the at sign (@) in a batch file and what does it do?](https://stackoverflow.com/questions/21074863/what-is-the-at-sign-in-a-batch-file-and-what-does-it-do) – user202729 Aug 21 '19 at 03:03
  • @user202729 do you really think I'm describing that thing?... Even though I can draw a conclusion on how it works base on my experiment, I wouldn't just set off without an exact behaviour description. – karatoga Aug 21 '19 at 03:08
  • I didn't realize that your question also ask for usage in the middle of the command line. In this case @ has no special meaning, just read the docs of the command invoked. – user202729 Aug 21 '19 at 03:16
  • possible duplicate , [What does the “@” symbol do in Powershell?](https://stackoverflow.com/questions/363884/what-does-the-symbol-do-in-powershell) – Modro Aug 21 '19 at 08:09

1 Answers1

4

When invoking cl.exe, a @-prefixed filename denotes a response file, which is a text file that contains what would normally be command-line arguments, which "can be useful if your command-line arguments exceed 127 characters."

In PowerShell, where @ is a metacharacter (a character with special meaning), you need to escape it as `@ or make it part of the quoted string, which should also work from cmd.exe / a batch file:

# PowerShell

# Escape @ as `@
cl `@"F:\x\cc.txt"

#`# Alternatively, make @ part of the quoted string,
#   which also works from cmd.exe / a batch file.
cl "@F:\x\cc.txt"

The above use of @, as part of an argument, is specific to cl.exe, the program being invoked.

By contrast, using @ at the start of a command is (always) interpreted by the calling shell (cmd.exe or PowerShell):

  • cmd.exe: @ at the start of a command suppresses echoing that command before printing its output (it's like executing echo off beforehand, but scoped to the command at hand)

    • Therefore, executing @"F:\x\cc.txt" by itself executes "F:\x\cc.txt" - which opens that file for editing - without echoing the command being executed first. (Note that without the @ the command would only be echoed when executed from a batch file that does not start with @echo off.)
  • PowerShell: @ at the start of a statement can only initiate one of the following constructs:

    • a here-string (@"<newline>...<newline>"@ or @'<newline>...<newline>'@)
    • an array-subexpression operation (@(<command...>))

    • Therefore, trying to execute @"F:\x\cc.txt" by itself causes a syntax error.

mklement0
  • 382,024
  • 64
  • 607
  • 775