cmd

New line as a delimeter of FOR loop

﹥>﹥吖頭↗ 提交于 2020-01-11 10:22:32
问题 I am new to batch script, and I am trying to parse a file that has key value (kind) of pairs delimited by new line. For example: the value of abc 1234 the value of def 5678 the value of ghi 9876 I would like to read this file using new line as delimited so that I can access the values. Something like for /f "tokens=1,2,3 delims='\n'" %%i in ('findstr /C:the value of abc 'filepath') do echo %%j 回答1: You can't set 'new line' as delimiter. Try this: @echo off &setlocal for /f "tokens=1*delims=:"

New line as a delimeter of FOR loop

帅比萌擦擦* 提交于 2020-01-11 10:22:08
问题 I am new to batch script, and I am trying to parse a file that has key value (kind) of pairs delimited by new line. For example: the value of abc 1234 the value of def 5678 the value of ghi 9876 I would like to read this file using new line as delimited so that I can access the values. Something like for /f "tokens=1,2,3 delims='\n'" %%i in ('findstr /C:the value of abc 'filepath') do echo %%j 回答1: You can't set 'new line' as delimiter. Try this: @echo off &setlocal for /f "tokens=1*delims=:"

Unzip file error when running VBS script from a batch in Windows 10

前提是你 提交于 2020-01-11 07:37:11
问题 When running the VBS unzip code batch in Win 10, I'm getting the error below. What can be a reason for this, given it was reported working before by others? Changing target directories or explicitly setting them doesn't affect the error. @echo off setlocal enabledelayedexpansion cd /d %~dp0 set vbs="%temp%\_.vbs" call :UnZipFile "E:\Temp\" "%USERPROFILE%\Downloads\archive.zip\" exit /b :UnZipFile <ExtractTo> <newzipfile> if exist %vbs% del /f /q %vbs% >%vbs% echo Set fso = CreateObject(

How to kill a process based on its image / file path?

纵饮孤独 提交于 2020-01-11 07:23:50
问题 How to kill a task based on the path of the executable? The usage of taskkill /F /IM "app.exe" doesn't work in this case because there are other programs running that have the same image/process/file name, but are totally different executables. The paths are different and the .exe files with same file name are different, too. Something like "taskkill /F /IM "C:\path\to\exe\app.exe" would be ideal. 回答1: Using WMIC , as suggested in the comments by Squashman, you can do it as a single command:

How to execute a batch file on uninstall in Inno Setup?

隐身守侯 提交于 2020-01-11 06:31:04
问题 I'm using code from How do you execute command line tools without using batch file in Inno Setup response to execute all my batch files on installation (before, after). No I want to execute them just when user click "YES" to uninstaller , but can't find a way to do it. It executes before the confirmation Here is my code from [Code] section: function InitializeUninstall(): Boolean; var ResultCode : Integer; begin Result := True; Exec(ExpandConstant('{app}\scripts\unset.bat'), '', '', SW_HIDE,

How to write console output to a text file in cpp?

亡梦爱人 提交于 2020-01-11 05:30:20
问题 I'm trying to write console data into a separate text file in cpp. Anybody help me with sample code. 回答1: There are various ways to do this. You could redirect it from the command line with programname > out.txt . Or you could use freopen("out.txt","w",stdout); at the start of your program. 回答2: If you want to write from your own process, I'd suggest a simple print method void print(const string str, ostream & output) { output << str; } Then you can call print("Print this", cout); for console

How to create a Simple Build Script for Visual Studio from the Command Line?

那年仲夏 提交于 2020-01-11 05:13:10
问题 I have a lot of Visual Studio Project Solutions in multiple directories (all with the extension .sln) and I want to write a simple batch script that will automatically build all solutions listed in the batch file. I am able to manually build a solution by starting up the Visual Studio Command Prompt (which is just a command-line instance with the following command executed "%comspec%" /k "C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86 After which I then build the project

Windows batch file to get C:\ drive total space and free space available

杀马特。学长 韩版系。学妹 提交于 2020-01-11 03:25:07
问题 I need a bat file to get C:\ drive total space and free space available in GB (giga bytes) in a Windows system and create a text file with the details. Note: i dont want to use any external utilities. 回答1: cut 9 digits of the size by bytes to get the size in GB: @echo off & setlocal ENABLEDELAYEDEXPANSION SET "volume=C:" FOR /f "tokens=1*delims=:" %%i IN ('fsutil volume diskfree %volume%') DO ( SET "diskfree=!disktotal!" SET "disktotal=!diskavail!" SET "diskavail=%%j" ) FOR /f "tokens=1,2" %

How to write an XML tag with double quotes using command prompt echo command

落爺英雄遲暮 提交于 2020-01-10 05:25:08
问题 Good afternoon, I would like to add the simpliest tag into a file, using a CMD batchfile, but it seems that the double quotes are spoiling the party: From other StackOverflow posts I am aware of the double quote state machine and the usage of ^" (^ as an escape character). Still I can't make it work: Hereby my attempts (with their results): C:\>echo <tag variable="value"> // very naïve The syntax of the command is incorrect. C:\>echo "<tag variable="value">" // let's use quotes for delimiting

Findstr - Return only a regex match

二次信任 提交于 2020-01-10 05:02:06
问题 I have this string in a text file ( test.txt ): BLA BLA BLA BLA BLA Found 11 errors and 7 warnings I perform this command: findstr /r "[0-9]+ errors" test.txt In order to get just 11 errors string. Instead, the output is: Found 11 errors and 7 warnings Can someone assist? 回答1: The findstr tool cannot be used to extract matches only. It is much easier to use Powershell for this. Here is an example: $input_path = 'c:\ps\in.txt' $output_file = 'c:\ps\out.txt' $regex = '[0-9]+ errors' select