简体   繁体   中英

How do I concatenate contents of a file to an environment variable in Windows Command prompt?

Assuming 'paths' is a file containing all the paths I need to write to the environment variable CLASSPATH , appended in the right format. I essentially need Windows equivalent of

CLASSPATH=$(cat paths)

In accordance with this answer I tried doing the below:

for /f "delims=" %A in ('cat paths.txt') do @set CLASSPATH=%A

(paths.txt has all the paths in the right format) but it does not work. Echoing '%CLASSPATH%' still gives me nothing. What am I doing wrong?

This in a .bat file would produce p1;p2;p3;

@echo off
setlocal enabledelayedexpansion
set CLASSPATH=
for /f "delims=" %%A in (paths.txt) do set "CLASSPATH=!CLASSPATH!%%A;"
echo %CLASSPATH%

rem to make it a permanent global
setx CLASSPATH %CLASSPATH%

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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