首页 > 解决方案 > 使用批处理文件,如何写入位置存储在变量中的文件?

问题描述

我想创建一个名为“server.cfg”的文件并将其放在路径存储在变量中的位置。我编写了下面的代码来尝试完成此操作,但脚本没有使用变量,而是在与脚本相同的文件夹中创建了一个名为“server”的文件。

:: Set the data variable with the folder name where server.cfg file will be (check the example)
:: example SET data=server-dataV1
SET data= server-dataV1.2
SET server = %data%\resources\server.cfg

echo # Only change the IP if you're using a server with multiple network interfaces, otherwise change the port only. >> server
echo endpoint_add_tcp "0.0.0.0:30120" >> server
echo endpoint_add_udp "0.0.0.0:30120" >> server
echo >> server
echo set mysql_connection_string "mysql://root:12345@localhost/es_extendedv1?charset=utf8mb4" >> server
echo set mysql_slow_query_warning 200000 >> server

标签: batch-file

解决方案


不幸的是,目前尚不清楚您要达到的目标,所以这是我最好的猜测。

@Rem Set the data variable with the folder name where server.cfg file will be (check the example)
@Rem Example: Set "data=server-dataV1"

@Set "data=server-dataV1.2"
@Set "server=%data%\resources\server.cfg"

@(
    Echo # Only change the IP if you're using a server with multiple network interfaces, otherwise change the port only.
    Echo endpoint_add_tcp "0.0.0.0:30120"
    Echo endpoint_add_udp "0.0.0.0:30120"
    Echo=
    Echo set mysql_connection_string "mysql://root:12345@localhost/es_extendedv1?charset=utf8mb4"
    Echo set mysql_slow_query_warning 200000
) 1> "%server%"

推荐阅读