batch-file

Windows Batch Variable within variable

隐身守侯 提交于 2020-01-09 11:24:48
问题 In windows batch could you set a variable within a variable? Explained: So the %num% is within the variable. set num=5 set cnum=test set h1=%c%num%% Is it possible to make the percents work like parenthesis? The output should be h1=test Any help would be appreciated. 回答1: Your example in your question is a mess, but I think I understand what you are looking for: @echo off setlocal set C1=apple set C2=orange set C3=banana set num=2 :: Inefficient way without delayed expansion :: This will be

Windows Batch Variable within variable

和自甴很熟 提交于 2020-01-09 11:24:09
问题 In windows batch could you set a variable within a variable? Explained: So the %num% is within the variable. set num=5 set cnum=test set h1=%c%num%% Is it possible to make the percents work like parenthesis? The output should be h1=test Any help would be appreciated. 回答1: Your example in your question is a mess, but I think I understand what you are looking for: @echo off setlocal set C1=apple set C2=orange set C3=banana set num=2 :: Inefficient way without delayed expansion :: This will be

Use a variable in a 'for' loop

情到浓时终转凉″ 提交于 2020-01-09 11:24:06
问题 I have following code: @echo off SET ITER=0 for %%i in (%*) do ( SET ITER+=1 ECHO %ITER% ) The output is (for three arguments): 0 0 0 Expected output: 1 2 3 Why can't I access the updated variable in the for loop? 回答1: Expansion of variables with percents is done before a statement/block is executed. So in your case the complete block is expanded before the echo %ITER% is executed, to constant echo 0 . The variable ITER itself is updated in the loop properly. To avoid this, you could use the

Use a variable in a 'for' loop

醉酒当歌 提交于 2020-01-09 11:22:05
问题 I have following code: @echo off SET ITER=0 for %%i in (%*) do ( SET ITER+=1 ECHO %ITER% ) The output is (for three arguments): 0 0 0 Expected output: 1 2 3 Why can't I access the updated variable in the for loop? 回答1: Expansion of variables with percents is done before a statement/block is executed. So in your case the complete block is expanded before the echo %ITER% is executed, to constant echo 0 . The variable ITER itself is updated in the loop properly. To avoid this, you could use the

Restore default working dir if bat file is terminated abruptly

。_饼干妹妹 提交于 2020-01-09 07:55:06
问题 I have a scenario where during execution of a batch file, it navigates to a different folder (say to "../asdf"); and at the end of execution it will set the current working dir as the same folder from where the user called the .bat file. But if the user terminates the batch processing before it is complete, the cmd show the current working dir (say "../asdf"). But in my case, I need to restore the working dir to the default/predefined one. Is it possible? Batch file is written by me, so I can

how to get a pc list that have a service running on each pc?

喜夏-厌秋 提交于 2020-01-08 04:19:09
问题 I m using psexec to auto run from cmd on all PCs on our network to check if certain process is running or not. but i wannt a list with all pc name that has the service running on. how can i do it from powershell? this is what i m running now. 2 batch files and 1 text file. get.bat tasklist | findstr pmill.exe >> dc-01\c$\0001.txt run_get.bat psexec @%1 -u administrator -p password -c "C:\get.bat" pclist.txt what i got from this in result are just all pmill.exe , i m wondering if there is

how to get a pc list that have a service running on each pc?

拥有回忆 提交于 2020-01-08 04:18:49
问题 I m using psexec to auto run from cmd on all PCs on our network to check if certain process is running or not. but i wannt a list with all pc name that has the service running on. how can i do it from powershell? this is what i m running now. 2 batch files and 1 text file. get.bat tasklist | findstr pmill.exe >> dc-01\c$\0001.txt run_get.bat psexec @%1 -u administrator -p password -c "C:\get.bat" pclist.txt what i got from this in result are just all pmill.exe , i m wondering if there is

replace string in csv file using batch file

巧了我就是萌 提交于 2020-01-07 14:20:44
问题 I have a csv file with 18 fields. I need to copy the file to a txt file, delete the first four lines, replace the data in field #8, and save the file with a new name. The data in field #8 is an integer (for example, 1, 2, 3, etc). Each integer needs to be replaced with a separate value (for example, I need to replace 1 with 1005 and 3 with 1008). I am trying to modify/fix the following batch file: @echo off More +4 datatest.csv > datacopy.txt ( FOR /f "tokens=8 delims=," %%h in (datacopy.txt)

replace string in csv file using batch file

坚强是说给别人听的谎言 提交于 2020-01-07 14:20:13
问题 I have a csv file with 18 fields. I need to copy the file to a txt file, delete the first four lines, replace the data in field #8, and save the file with a new name. The data in field #8 is an integer (for example, 1, 2, 3, etc). Each integer needs to be replaced with a separate value (for example, I need to replace 1 with 1005 and 3 with 1008). I am trying to modify/fix the following batch file: @echo off More +4 datatest.csv > datacopy.txt ( FOR /f "tokens=8 delims=," %%h in (datacopy.txt)

How do you use a batch to modify certain columns in a CSV file?

空扰寡人 提交于 2020-01-07 09:25:13
问题 I have a simple CSV file with six values per row (%a-%f) The %a is text string the other values are all integers. My problem is that for values %d and %e cannot be odd and must be rounded up. Should I search for each odd integer one at a time or is there a simpler way? My CSV file looks like this: ww-xx-yy-zzz,1,2,3,4,5 回答1: The following script accomplishes what you are trying to do: @echo off setlocal EnableExtensions DisableDelayedExpansion rem Define constants here: set "CSVFILE=data.csv"