![]() ![]() Wscript.Echo "Size: " & FormatNumber(lngSize, 0) ![]() Wscript.Echo "DeviceID: " & objDrive.DeviceID ("SELECT * FROM Win32_LogicalDisk WHERE DeviceID = 'C:'") Set colDrives = objWMIService.ExecQuery _ Set objWMIService = GetObject("winmgmts:" _ For example: Option Explicitĭim strComputer, objWMIService, colDrives, objDriveĭim lngSize, lngFree, lngUsed, dblPercent I think a VBScript program is the best solution. Read also the Microsoft article about Using Command Redirection Operators.I've never seen math done in a batch file, even adding two integers. Please note that the surrounding straight single quotes make the difference for FOR if the string should be interpreted as file name of which lines to process or a command line to execute in a separate command process in background of which output to capture from handle STDOUT and to process line by line.įor understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully. In both batch code blocks the file name Input.txt can be also replaced by: 'command line which outputs the text to process' With this batch code loop variable J can have also no string assigned or a string on which first batch code would exit with a syntax error. If "!Number:~0,1!" NEQ "!DoubleQuote!" echo !Number!>Output.txt Setlocal EnableExtensions EnableDelayedExpansionįor /F "tokens=1,2" %%I in (Input.txt) do ( The number without surrounding double quotes is appended to file Output.txt.Ī bit slower but more safe would be following code: off Therefore this comparison is only true if J has the number without surrounding double quotes. The surrounding double quotes are also taken into account on comparing two strings with IF command. So a comparison is made which compares the value of loop variable J with the value of loop variable J without surrounding double quotes. If this IF condition is true, the batch code expects that the second loop variable J is also set and has either just the number of interest or the number of interest in double quotes. The IF condition in body command block compares case-sensitive the first space/tab delimited string from current line with RequestId: to verify if this line contains the number of interest. ![]() The commands in body command block of FOR are executed when at least 1 token could be assigned to first loop variable I. The first space/tab delimited string is assigned to loop variable I and because of tokens=1,2 the second one is assigned to loop variable J being the next character after I in ASCII table. It splits up each line into substrings (tokens) using normal space and horizontal tab as string delimiter. The FOR command processes each line from file Input.txt not being empty or starting with a semicolon. On execution of the batch file from within a command prompt window with current directory being the directory with Input.txt and GetNumbers.bat by typing batch file name and hitting key RETURN there was no error displayed and the batch file created Output.txt with the two lines: 1892 offįor /F "tokens=1,2" %%I in (Input.txt) do if "%%I" = "RequestId:" if %%J = %%~J echo %%J>Output.txt The batch code below was written into file GetNumbers.bat stored in same directory as Input.txt. Here's what I've tried: for /f "tokens=2 delims=:" %%b in ('"C:\program Files\command.exe"'|findįor testing the batch code below I created the file Input.txt with the lines: No value provided for Subject Attribute ST, skipped So the code should extract out the number after RequestId: RequestId: 1892Īfterwards it will take the first number and last number of the file and echo it out.Į.g Please approve the certificates from Request ID 900 to 920. Please approve the certificates before pressing enter. Generating certificate request and key for xxxx No value provided for Subject Attribute ST, skippedĬertificate request is pending: Taken Under Submission (0) Here's the output of the commandline after executing the script C:\OpenSSL\bin>RequestCert.bat I want the batch file to extract out all the numbers and store it in a file line by line with the filename called RequestID. I have a batch script that will submit certificate request and it will return a multiple RequestId in the CMD. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |