batch-file

How to get Java version in a batch script subroutine?

馋奶兔 提交于 2020-01-06 06:44:54
问题 From this question: for /f "tokens=3" %%g in ('java -version 2^>^&1 ^| findstr /i "version"') do ( @echo Output: %%g set JAVAVER=%%g ) How can I put this into a subroutine and call it, passing a path to the java executable? Here's an example of my problem: @echo off setlocal enabledelayedexpansion call :GET_JAVA_VER "java" goto END :GET_JAVA_VER for /f "tokens=3" %%g in ('%1 -version 2^>^&1 ^| findstr /i "version"') do @echo %%g %1 -version 2>&1 | findstr /i "version" goto :EOF :END endlocal

Batch - syntax error when trying to echo greater-then sign (>)

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-06 06:05:35
问题 I have the following stript: @ECHO OFF SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION SET /A countArgs=1 ... SET /A countArgs+=1 CALL :error "!countArgs!. Argument ^-^> bla" EXIT /B 1 ... :error ECHO ERROR ECHO %~1 EXIT /B 0 But the 2. ECHO -line in the :error routine echo s nothing. When I reduce the CALL argument string to "!countArgs!. Argument ^-^>" i get a syntax error and when i reduce it to "!countArgs!. Argument ^-" or even "!countArgs!. Argument -" it works properly. According to

What is the reason for nodemon working in cmd but not in a batch file?

♀尐吖头ヾ 提交于 2020-01-06 05:37:27
问题 I am in the process of making a discord bot. All of the code that I have written for the bot works except for the batch file that is supposed to run it. Originally I was just using the node command and when I opened cmd, navigated to the folder, and typed it manually it worked fine, but when I put that same code into a batch file it gave me this error: 'node' is not recognized as an internal or external command, operable program or batch file. This is all the code for that batch file: @echo

Remove all lines which do not contain a period

假装没事ソ 提交于 2020-01-06 05:25:54
问题 I have a text like this in %userprofile%\i.txt : PDF wikkipedia.ord notavalidURL snapfish.com .tunnelbear.com mail.google.com/mail/u/0/#inbox I want to convert it to a string like this: wikkipedia.ord snapfish.com .tunnelbear.com mail.google.com/mail/u/0/#inbox! I want to do this using native cmd.exe syntax only (no powershell, cygwin, etc.). So I know that I can do this: @echo off setlocal EnableDelayedExpansion set row= for /f %%x in (%userprofile%\i.txt) do set "row=!row!%%x" echo %row% >

Local variable in FOR DO Statement

微笑、不失礼 提交于 2020-01-06 04:51:25
问题 does the variable 'var' gets destroyed before displaying its value? @echo off FOR /f "tokens=* delims=" %%G IN ('dir') DO ( set var=%%G echo %var% ) 回答1: This will never work since the reference to %var% is resolved when the body of the loop is parsed. You have to enable delayed variable expansion and use !var! instead: @ECHO OFF SETLOCAL EnableDelayedExpansion FOR /F "tokens=* delims= " %%G IN ('dir') DO ( SET VAR=%%G ECHO !VAR! ) ENDLOCAL You can read all about it by type SET /? at a

How to download MP3 using youtube-dl with a batch file?

你。 提交于 2020-01-06 04:37:33
问题 This is a continuation on my previous question: How to create a youtube downloader gui with youtube-dl in batch I have found out how the downloading of the video works, which means I could somehow enter the command line using Notepad. Here is my current code: cls @echo off title youtube downloader :downloader echo youtuber downloader!!! pause cls set "site=" set /p "site=Please enter youtube link here> " If Not Defined site cls & goto downloader echo Do you want to download "%site%" as mp3?

Why is most of the output not being redirected to the file?

自作多情 提交于 2020-01-06 04:31:28
问题 I have a batch script that opens a PS session as bypass policy and executes whatever the PS script needs to execute set "psFile=.\main.ps1" Powershell.exe -ExecutionPolicy ByPass -Command "&{%psFile% %2 %3 %4 %5 %6 | Tee-Object -FilePath log.txt}" I am getting what I want: output to both console AND file. however, when I opened the file after the execution was finished, it only contained like one line from everything else that was printed on the console. 99% of the output was not redirected

Grepping `reg query` result value?

强颜欢笑 提交于 2020-01-06 04:27:11
问题 Consider the following result from a hypothetical reg query : ..>reg query HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\MediaPlayer /v "I nstallation Directory" HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\MediaPlayer Installation Directory REG_EXPAND_SZ %ProgramFiles%\Windows Media Play er How do I grep the output so that I can assign the actual value of the setting ( %ProgramFiles%\... ) into a variable (or temp file)? 回答1: example for batch files: @FOR /F "tokens=2* " %%A IN (

Batch to find highest version-string from amount of lines

非 Y 不嫁゛ 提交于 2020-01-06 04:27:07
问题 I need to determine what's the highest installed version of LocalDB within a batch script and set the whole version string into a variable. sqllocaldb versions produces an out put like: Microsoft SQL Server 2012 (11.0.5058.0) Microsoft SQL Server 2014 (12.0.2000.8) The order of the version string is not necessarily ascending. Need some help to set the highest server version into a variable (in this example 12.0.2000.8). 回答1: you need to invoke the command and parse the returned string, with a

Bypass limit of 239 characters of sqlplus

妖精的绣舞 提交于 2020-01-06 03:47:46
问题 I loop on each line of a file, and each line has more than 3000 characters length. But when I execute my .bat, and after the SQLPlus connection, the console window contains the message: http://puu.sh/l6vOI/6bba21982b.png Traduction : the beginning of the string " " SO100ACa4 ... " is too long - the maximal size is 239 characters. I tested using Set VERIFY OFF and SET LINESIZE 4000 , but nothing worked. Here is a part of my batch script: for /f "delims=" %%f IN ('dir /b "%NomFichierU%*.txt"')