delayedvariableexpansion

Why setlocal interferes with chdir in windows batch files?

孤街醉人 提交于 2020-06-08 16:50:10
问题 If I run the batch file setlocal chdir .. the directory is not changed, but if I run setlocal endlocal chdir .. it works normally. This must be exactly what is expected with setlocal. However, it is not entirely obvious when you read the definition of setlocal, which is related to how the environment variables are seen. I am hoping that this is a good occasion to explain what setlocal actually does and why it interferes with chdir. 回答1: The HELP documentation for SETLOCAL ( help setlocal or

Windows CMD Batch Script - how to avoid cutting the mark “!” in the loop

五迷三道 提交于 2020-06-01 07:41:08
问题 I have XML file myConfig.xml. <?xml version="1.0" encoding="UTF-8" standalone="no"?> <test1.test.com id="valueTest1"/> <test2.test.com id="valueTest1"/> <test3.test.com id="valueTest1"/> <installpath>C:\Temp\TESTxyz</installpath> <userInput> <entry key="myPassword" value="Qwerty123!"/> <entry key="myLogin" value="John"/> </userInput> I need in CMD in batch script change value in . @echo off setlocal EnableDelayedExpansion set newValueInstallpath="D:\Work" (for /F "delims=" %%a in (myConfig

Variables are not behaving as expected

不打扰是莪最后的温柔 提交于 2020-01-30 12:55:26
问题 I've been wrestling trying to get the syntax right on this batch file and I cannot figure out why some things aren't working. The variable i is not getting incremented each time I do it. Concatenation on strc doesn't seem to concatenate. Here is my code: set i=0 set "strc=concat:" for %%f in (*.mp4) do ( set /a i+=1 set "str=intermediate%i%.ts" set strc="%strc% %str%|" ffmpeg -i "%%f" -c copy -bsf:v h264_mp4toannexb -f mpegts "%str%" ) set strc="%strc:-1%" ffmpeg -i "%strc%" -c copy -bsf:a

Variables are not behaving as expected

落爺英雄遲暮 提交于 2020-01-30 12:54:39
问题 I've been wrestling trying to get the syntax right on this batch file and I cannot figure out why some things aren't working. The variable i is not getting incremented each time I do it. Concatenation on strc doesn't seem to concatenate. Here is my code: set i=0 set "strc=concat:" for %%f in (*.mp4) do ( set /a i+=1 set "str=intermediate%i%.ts" set strc="%strc% %str%|" ffmpeg -i "%%f" -c copy -bsf:v h264_mp4toannexb -f mpegts "%str%" ) set strc="%strc:-1%" ffmpeg -i "%strc%" -c copy -bsf:a

Fix a batch script to handle closing parentheses inside an if block

霸气de小男生 提交于 2020-01-25 03:10:12
问题 I have a batch script to run different PHP versions under different environments. @ECHO OFF setlocal EnableExtensions EnableDelayedExpansion IF "%ANSICON%" == "" ( php7 %* ) ELSE ( php5 %* ) The problem is it breaks on the first unescaped closing parenthesis as it matches the opening parenthesis in IF "%ANSICON%" == "" ( . C:\>php -r echo'()'; ' was unexpected at this time. C:\>php -r echo'(())'; )' was unexpected at this time. The line setlocal EnableExtensions EnableDelayedExpansion is new

Modify for loop to not use delayedexpansion in batch script

偶尔善良 提交于 2020-01-17 10:54:10
问题 In my efforts to understand the for..do loops syntax and their use of %% variables. I have gone through 2 specific examples/implementations where the one for loop does not use DELAYEDEXPANSION and another where it does use DELAYEDEXPANSION with the ! notation. The 1st for loop appears to be compatible with older OSs like the Windows XP whereas the 2nd for loop example does not. Specifically, the 1st for loop example is taken from this answer (which is related to this) and the 2nd for loop

Nested variable name using EnableDelayedExpansion

烈酒焚心 提交于 2020-01-03 02:43:05
问题 I am working on a script to get max lengths of each column, I'm trying to store lengths of max length in _c1...n vars. number of columns unknown. I was able to get length for each column, create variables to store each with set _c!i! = !n!, n is the length but in order to set the max length for a particular column I need to compare current with max and use something like !_c!!i!! which doesn't work, any ideas how to refer a variable which part of it's name coming from another variable? Thanks

Dos inline IF test for errorlevel, without use of Delayed Expansion

走远了吗. 提交于 2020-01-02 12:14:32
问题 Is there anyway to do the below without delayed expansion (one line, broken for readability)? %comspec% /v:on /c %windir%\System32\reg.exe import c:\temp\test.reg & if !errorlevel! neq 0 pause If it were an echo, I know that call can be used, but doesn't seem to be available for use with the if . 回答1: One way is to use this older syntax: %comspec% ... & if errorlevel 1 pause In this case, a special variant of if statement is used, one that tests the current errorlevel state. Another option