0

所以,我在将其中一行回显到文件时遇到问题。代码如下:

IF NOT EXIST "%rutaSteamIdle%\tf2idle.ini" (
(
ECHO [Settings]
ECHO steam_location = C:\Program Files (x86)\Steam
ECHO secondary_steamapps_location = 
ECHO sandboxie_location = C:\Program Files\Sandboxie
ECHO api_key = 02FE9AB5998EA5F8A3E0DA7C4C47F3C7
ECHO backpack_viewer = Backpack.tf
ECHO launch_options = +exec idle.cfg -textmode -nosound -low -novid -nopreload -nojoy -sw +sv_lan 1 -width 640 -height 480 +map itemtest
ECHO launch_delay_time = 120
ECHO log_file_formatting = {date}, {time}, {itemtype}, {item}, {id}, {account}{nline}
ECHO easy_sandbox_mode = no
ECHO sys_tray_notifications = hats,tools
ECHO close_to_tray = False
ECHO log_web_view = On
ECHO log_web_view_port = 5000
ECHO ui_no_of_columns = 2
ECHO ui_window_size = (1024, 768)
ECHO ui_account_box_font_size = 12
ECHO ui_account_box_icon_size = 40
ECHO ui_account_box_icon = 
ECHO ui_log_entry_toggles = system,hats,weapons,tools,crates
ECHO log_poll_time = 1
ECHO ui_log_background_colour = 000000
ECHO ui_log_font_colour = FFFFFF
ECHO ui_log_font_size = 12
ECHO ui_log_font_family = TF2 Build
ECHO ui_log_font_style = 0
ECHO ui_log_font_weight = 50
ECHO ui_log_font_strikeout = False
ECHO ui_log_font_underline = False
)>>"%rutaSteamIdle%\tf2idle.ini"
)

运行此程序时,我得到“闪烁”(cmd窗口在关闭之前保持打开一秒钟)以下错误:

\Steam was unexpected at this time.

我在这里错过了什么吗?如果我这样写:

ECHO steam_location = "C:\Program Files (x86)\Steam"

它回声正确,但遗憾的是这是我做不到的。

4

2 回答 2

1

这是因为 Steam 路径包含右括号。你需要像这样逃避它:

ECHO steam_location = C:\Program Files (x86^)\Steam

cmd的解析器对这些东西不是很好。这是在带括号的块内,因此第一个未转义(或未引用,但引用在这里不起作用,因为echo也会输出引号)右括号将结束该块。同一行中之后的部分将被解释为下一个命令,在这种情况下\Steam会导致您收到错误消息。

于 2013-01-29T07:24:49.350 回答
0

你也可以试试这个...

SET "steam_location=C:\Program Files (x86)\Steam"
ECHO %steam_location%

它会给你输出

C:>ECHO C:\Program Files (x86)\Steam

C:\Program 文件 (x86)\Steam

我希望这有效:)

于 2013-01-29T09:30:11.250 回答