Briefly - is there a simple svn command to tell us the "most recently changed branch"?
In more depth, as part of our build process, we're trying to detect the most recently-changed branch in Subversion, in order to perform further processing on that branch.
For example, if someone added the file:
http://server/svn/project/branches/Integration1/newfile.txt
we'd want to be able to determine the string:
http://server/svn/project/branches/Integration1
that is, the parent folder of the most recent change.
The closest we can find is to execute the following command:
svn log --verbose --limit 1 http://server/svn/project/
but it then gives a 4-line output that we'd need to parse, using batch.
We have a Jenkins build server with the Subversion plugin installed, which can detect the change to the overall subversion repository, but it only gives us the environment variables SVN_URL and SVN_REVISION, neither of which address our goal.
I would use:
svn log --verbose --quiet --limit 1 "http://server/svn/project/"
So you get rid of any commit log messages and have just a list of modified paths and a header. Then use a for /F loop loop to capture the paths:
rem // Capture output of `svn log`, skip header and hyphen-only lines:
for /F "skip=3 eol=- tokens=1*" %%I in ('
svn log --verbose --quiet --limit 1 "http://server/svn/project/"
') do echo(%%J
The tricky part is to derive the common root path of multiple items, which might be done like in the following script, for instance (see all the explanatory rem remarks in the code; provide the repository path http://server/svn/project/ as the first command line argument):
#echo off
setlocal EnableExtensions DisableDelayedExpansion
rem // Define constants here:
set "_REPOPATH=%~1" & rem // (take the first argument as the repository path)
rem // Clear buffer for common root path:
set "COMM="
rem // Clear all variables beginning with `$`:
for /F "delims=" %%K in ('set $ 2^> nul') do set "%%K="
rem // Capture output of `svn log`, skip header and hyphen-only lines:
for /F "skip=3 eol=- tokens=1*" %%I in ('
svn log --verbose --quiet --limit 1 "%_REPOPATH%"
') do (
rem // Store currently iterated path:
set "ITEM=%%J"
rem // Check whether buffer for common root path is empty:
if not defined COMM (
rem // Buffer is empty, hence this is the first iteration:
set "COMM=%%J"
) else (
rem // Otherwise, store each `/`-separated path element in array `$ITEM[]`:
set /A "IDX=0"
setlocal EnableDelayedExpansion
for %%K in ("!ITEM:/=" "!") do (
for %%L in (!IDX!) do (
endlocal
set "$ITEM[%%L]=%%~K"
set /A "IDX+=1"
setlocal EnableDelayedExpansion
)
)
endlocal
rem // Store each element of buffered common root path in array `$COMM[]`:
set /A "CNT=IDX-1, IDX=0"
setlocal EnableDelayedExpansion
for %%K in ("!COMM:/=" "!") do (
for %%L in (!IDX!) do (
endlocal
set "$COMM[%%L]=%%~K"
set /A "IDX+=1"
setlocal EnableDelayedExpansion
)
)
rem // Determine the lower number of elements of `$ITEM[]` and `$COMM[]`:
if !CNT! geq !IDX! set /A "CNT=IDX-1"
rem // Loop through both arrays and write all common elements to buffer:
set "COMM=" & set "FLAG=#"
for /L %%L in (0,1,!CNT!) do (
if /I "!$ITEM[%%L]!" == "!$COMM[%%L]!" (
rem // The flag is just necessary to stop at the first difference:
if defined FLAG set "COMM=!COMM!!$COMM[%%L]!/"
) else set "FLAG="
)
rem // Transport the built common root path buffer beyond `endlocal`:
for /F "delims=" %%K in (""!COMM!"") do (
endlocal & set "COMM=%%~K"
)
)
)
setlocal EnableDelayedExpansion
if defined COMM (
rem // Check if there was only one path and just get get its parent in case:
if not "!COMM:~-1!" == "/" (
for %%K in ("!COMM:/=\!") do (
endlocal & set "COMM=%%~pK"
setlocal EnableDelayedExpansion
set "COMM=!COMM:\=/!"
)
)
rem // Return the finally retrieved common root path of all paths:
echo(!COMM:~1,-1!
)
endlocal
endlocal
exit /B
I don't know if that will work in your Jenkins environment, but here is what I would do in a standard (eg bash) shell. I use a terse svn log:
svn log ^/branches -l1 -q --incremental
Adding a pipe to parse it, the full command would be:
svn log ^/branches -l1 -q --incremental | sed -n "s/.*| \(.*\) |.*/\1/p"
Replace the caret (^) with http://server/svn/project/.
EDIT: to get the branch name, increase the verbosity of svn log with -v to print the modified paths, and adapt the sed command to extract the branch name. The following works for me:
svn log ^/branches -l1 -q -v | sed -n '4 s|.*/branches/||p'
or more aggressive:
svn log ^/branches -l1 -q -v | sed -nr '4 s|.*/branches/([^/]+).*|\1|p'
Related
I'm writing the universal batch script for a Git upload.
I want to specify the location of the Git executable, if user doesn't provide one/is not located by where command.
C:\>#echo off
set Windows=C:\Windows\System32
set where=%Windows%\where.exe
: --- Git location ---
set "Git=..." Executable
if %Git%==... (
set "Git=%where% git.exe" : <---
)
echo %Git%
where git.exe
%Git%
C:\Program Files (x86)\Git\cmd\git.exe
The problem is, that executing a variable is different than echoing it.
How can I make echo %Git% output C:\Program Files (x86)\Git\cmd\git.exe?
If you simply wanted to request from the end user the absolute path of the git executable, if it was not located in %Path%, then perhaps something like this may suit your purposes better:
#Echo Off
SetLocal EnableExtensions DisableDelayedExpansion
For %%G In ("git.exe") Do Set "Git=%%~$Path:G"
If Defined Git GoTo Main
Set /P "Git=Enter the absolute path of your chosen git executable>" || GoTo :EOF
For %%G In ("%Git:"=%") Do If /I "%%~nxG" == "git.exe" If "%%~aG" Lss "d" If "%%~aG" GEq "-" GoTo Main
GoTo :EOF
:Main
Echo The absolute path to your primary git executable is %Git%.&Pause
The last line is for demonstation only, you would obviously change that to:
"%Git%" [Args]
or:
Start "" "%Git%" [Args]
As an alternative, if you really wanted to use where.exe, which would give you the additional benefit of checking the current directory, as well as %Path%, but could grab the location of more than one matching file, just replace line 3 of the script above with:
Set "Git=" & For /F Delims^= %%G In ('%__AppDir__%where.exe "git.exe" 2^>NUL') Do If Not Defined Git Set "Git=%%~G"
Or:
Set "Git=" & For /F Delims^= %%G In ('%SystemRoot%\System32\where.exe "git.exe" 2^>NUL') Do If Not Defined Git Set "Git=%%~G"
In the case of multiple found files, this would define the variable with that which would be invoked by default should you have simply entered git.exe within that same environment.
I write two for loops to do data automation. While variables echoed well in each loop, the last step (data process using a well-written batch) keeps giving errors that variables set previous do not exist.
The code loops through the subfolders (q1, q2, etc.) under the directory. For each subfolder, there is another for loop to set several variables. I echoed three variables fine in loops.
However, when using a batch called abc.rb, the error is COM_M does not exist.
Actually, the error is all three variables do not exist.
setlocal ENABLEDELAYEDEXPANSION
for /f %%f in ('dir /ad /b ') do (
echo %%f
pause
pushd %%f
for %%a in (*.a*.dat) do (
set COM_DATA=%%a
echo !COM_DATA!
set COM_V=%%f\com-v.dat
echo !COM_V!
set COM_M=%%f\com-M.dat
echo !COM_M!
)
chdir
set fig=someA
set matrix=someB
rem use a written batch (called abc.rb) to process data
abc.rb -a !COM_DATA! -b !COM_V! -c !COM_M! -d !fig! -e !matrix!
popd
)
endlocal
Can anyone find any bugs? Thank you!
I am not sure why the need to pushd into the dir, but as far as I can see, there is only a need for a single for loop:
#echo off
setlocal enabledelayedexpansion
set "fig=someA"
set "matrix=someB"
for /R %%a in (*.a*.dat) do (
set "COM_DATA=%%a"
echo !COM_DATA!
set "COM_V=%%~dpacom-v.dat
echo !COM_V!
set COM_M=%%~dpacom-M.dat
echo !COM_M!
rem If abc.rb is is NOT a windows batch file, remove call below
call abc.rb -a "!COM_DATA!" -b "!COM_V!" -c "!COM_M!" -d !fig! -e !matrix!
)
If you require the pushd (which I doubt)
#echo off
setlocal enabledelayedexpansion
set "fig=someA"
set "matrix=someB"
for /R %%a in (*.a*.dat) do (
pushd "%%~dpa"
set "COM_DATA=%%a"
echo !COM_DATA!
set "COM_V=%%~dpacom-v.dat"
echo !COM_V!
set "COM_M=%%~dpacom-M.dat"
echo !COM_M!
rem If abc.rb is is NOT a windows batch file, remove call below
call abc.rb -a "!COM_DATA!" -b "!COM_V!" -c "!COM_M!" -d !fig! -e !matrix!
popd
)
The double quotes will help if the paths have whitespace, if your program has an issue with them, then you can remove them: abc.rb -a !COM_DATA! -b !COM_V! -c !COM_M! -d !fig! -e !matrix!
#echo off
setlocal ENABLEDELAYEDEXPANSION
set "fig=someA"
set "matrix=someB"
set "COM_V=com-v.dat"
set "COM_M=com-M.dat"
for /f %%f in ('dir /ad /b') do (
echo %%f
pause
if exist "%%~f\*.a*.dat" (
pushd "%%~f" && (
for %%a in (*.a*.dat) do (
set "COM_DATA=%%~a"
echo !COM_DATA!
)
chdir
rem use a written batch called abc.rb to process data
call abc.rb -a "!COM_DATA!" -b "!COM_V!" -c "!COM_M!" -d "!fig!" -e "!matrix!"
popd
)
)
)
endlocal
Issues:
If the nested for loop finds no files with the matched pattern of *.a*.dat, then the variables COM_DATA, COM_V and COM_M may not be defined or updated with a newer value.
Value of COM_DATA is a filename. Values of COM_V and COM_M is the parent folder name and filename, which is inconsistent. Based on the current directory, I would consider filenames as correct. This means that COM_V and COM_M never need to change.
If abc.rb is a batch-file, then you need to use call for the interpreter to return control back to the main script.
Changes:
Test if the file pattern exists, and run the code within the code block if true.
COM_V and COM_M moved out of the for loop as values never change.
Calling abc.rb as being a batch-file.
fig and matrix moved out of the for loop as values never change.
Double quote setting of variables and use of variables to avoid issues with spaces, special characters etc.
pushd && ( ensures the code within the parentheses is run only on success of changing directory.
Removed parentheses in the rem line. They may not cause a problem, though rem lines are parsed and can cause a syntax error. Suggest avoiding special characters in rem lines unless you intend to debug.
I am attempting to write a batch-file that leverages ffmpeg.exe to convert all files in a folder structure to mp3 format (specifically 128 KBps).
My batch-file is presently unable to process filenames (constructed by concatenating the %_SOURCE% and %%~F variables) containing certain special characters generating the following errors:
No such file or directory
… ellipsis sign
– en dash
— em dash
− minus sign
Invalid argument
‘ and ’ curved single quotation marks
“ and ” curved double quotation marks
Invalid argument (yet sometimes passes depending on where symbol is in the filename, for example, seems to work if placed between the n and t of Dont in C:\Users\Test\Documents\Input\Peter Bjorn And John - I Know You Dont Love Me.mp3)
- hyphen
! exclamation mark
~ tilde
' non-curved single quotation mark
= equals sign
+ plus sign
% percentage sign
( open bracket
How can I modify my batch-file script so that the %%~F variable escapes these characters correctly?
Example current filename input: C:\Users\Test\Documents\Input\Peter Bjorn And John - I Know You Don't Love Me.mp3
Example desired filename input: C:\Users\Test\Documents\Input\Peter Bjorn And John - I Know You Don"^'"t Love Me.mp3
Script (see line beginning C:\ffmpeg\bin\ffmpeg.exe):
#echo off
setlocal EnableExtensions DisableDelayedExpansion
rem // Define constants here:
set "_SOURCE=C:\Users\Test\Documents\Input" & rem // (absolute source path)
set "_TARGET=C:\Users\Test\Documents\Output" & rem // (absolute target path)
set "_PATTERN=*.*" & rem // (pure file pattern for input files)
set "_FILEEXT=.mp3" & rem // (pure file extension of output files)
pushd "%_TARGET%" || exit /B 1
for /F "delims=" %%F in ('
cd /D "%_SOURCE%" ^&^& ^(rem/ list but do not copy: ^
^& xcopy /L /S /Y /I ".\%_PATTERN%" "%_TARGET%" ^
^| find ".\" ^& rem/ remove summary line;
^)
') do (
2> nul mkdir "%%~dpF."
rem // Set up the correct `ffmpeg` command line here:
set "FFREPORT=file=C\:\\Users\\Test\\Documents\\Output\\ffreport-%%~F.log:level=32"
"C:\ffmpeg\bin\ffmpeg.exe" -report -n -i "%_SOURCE%\%%~F" -vn -c:a libmp3lame -b:a 128k "%%~dpnF%_FILEEXT%"
if not errorlevel 1 if exist "%%~dpnF%_FILEEXT%" del /f /q "%_SOURCE%\%%~F"
)
popd
endlocal
pause
#echo off
setlocal EnableExtensions DisableDelayedExpansion
rem // Define constants:
set "_SOURCE=C:\Users\Test\Documents\Input" & rem // (absolute source path)
set "_TARGET=C:\Users\Test\Documents\Output" & rem // (absolute target path)
set "_PATTERN=*.*" & rem // (pure file pattern for input files)
set "_FILEEXT=.mp3" & rem // (pure file extension of output files)
pushd "%_TARGET%" || exit /B 1
for /r "%_SOURCE%" %%F in ("%_PATTERN%") do (
set "_fullpath=%%~F"
set "_filename=%%~nF"
call :ffmpeg
)
popd
endlocal
pause
exit /b
:ffmpeg
setlocal EnableDelayedExpansion
rem // Get target path and log path:
for %%A in ("!_fullpath:%_SOURCE%=.!") do (
set "_logpath=%%~dpAffreport-!_filename!.log"
set "_targetpath=%%~dpA"
)
for %%A in (_logpath _targetpath) do if not defined %%A (
echo ERROR: %%A not defined.
exit /b 1
)
rem // Escape logpath:
set "_logpath=!_logpath:\=\\!"
set "_logpath=!_logpath::=\:!"
set "_logpath=!_logpath:'=\'!"
set "_logpath=!_logpath:%%=%%%%!"
rem // Set FFREPORT:
set "FFREPORT=file=!_logpath!:level=32"
rem // Make dir for the target file:
if not exist "!_targetpath!" md "!_targetpath!"
rem // Run ffmpeg command:
"C:\ffmpeg\bin\ffmpeg.exe" -hide_banner -report -n -i "!_fullpath!" -vn -c:a libmp3lame -b:a 128k "!_targetpath!\!_filename!%_FILEEXT%"
if not errorlevel 1 if exist "!_targetpath!\!_filename!%_FILEEXT%" del /f /q "!_fullpath!"
exit /b 0
Use of for /f with a command tends to alter filenames if
contains Extended ASCII such as the ellipsis.
Using a for /r to iterate the files gives better results
and have adjusted the code to handle the change.
Added the label :ffmpeg to make it easier for working with
the delayed expansion variables etc.
Added _logpath variable to store the log filepath with any
backslash, colon or single quote to be escaped with a backslash.
Percent signs are escaped by doubling up.
Added _targetpath variable to store the path to where ffmpeg
is to output the file. Used by md command to make a directory
structure like that of the input.
This may not solve all issues. Tried to do without delayed
expansion though always had some failures depending on special
characters i.e. %.
I'm trying to generate a war file in play application.
I am using starter java project: play-java-starter-example. Play version 2.6.2 in Windows.
I added the plugin play2war in project/plugins.sbt:
addSbtPlugin("com.github.play2war" % "play2-war-plugin" % "1.4.0")
After that I ran the following commands:
C:\project_name>sbt
[project_name]$ dist
It generates a zip file as it's supposed to.
The next step according to the official Doc is to execute a .bat file inside target/universal/[project_name]/bin
Im stuck at this step, execution of the script gives the following message:
console output
Here is the content of the .bat file generated by the dist command:
#REM play-java-starter-example launcher script
#REM
#REM Environment:
#REM JAVA_HOME - location of a JDK home dir (optional if java on path)
#REM CFG_OPTS - JVM options (optional)
#REM Configuration:
#REM PLAY_JAVA_STARTER_EXAMPLE_config.txt found in the PLAY_JAVA_STARTER_EXAMPLE_HOME.
#setlocal enabledelayedexpansion
#echo off
if "%PLAY_JAVA_STARTER_EXAMPLE_HOME%"=="" set "PLAY_JAVA_STARTER_EXAMPLE_HOME=%~dp0\\.."
set "APP_LIB_DIR=%PLAY_JAVA_STARTER_EXAMPLE_HOME%\lib\"
rem Detect if we were double clicked, although theoretically A user could
rem manually run cmd /c
for %%x in (!cmdcmdline!) do if %%~x==/c set DOUBLECLICKED=1
rem FIRST we load the config file of extra options.
set "CFG_FILE=%PLAY_JAVA_STARTER_EXAMPLE_HOME%\PLAY_JAVA_STARTER_EXAMPLE_config.txt"
set CFG_OPTS=
if exist "%CFG_FILE%" (
FOR /F "tokens=* eol=# usebackq delims=" %%i IN ("%CFG_FILE%") DO (
set DO_NOT_REUSE_ME=%%i
rem ZOMG (Part #2) WE use !! here to delay the expansion of
rem CFG_OPTS, otherwise it remains "" for this loop.
set CFG_OPTS=!CFG_OPTS! !DO_NOT_REUSE_ME!
)
)
rem We use the value of the JAVACMD environment variable if defined
set _JAVACMD=%JAVACMD%
if "%_JAVACMD%"=="" (
if not "%JAVA_HOME%"=="" (
if exist "%JAVA_HOME%\bin\java.exe" set "_JAVACMD=%JAVA_HOME%\bin\java.exe"
)
)
if "%_JAVACMD%"=="" set _JAVACMD=java
rem Detect if this java is ok to use.
for /F %%j in ('"%_JAVACMD%" -version 2^>^&1') do (
if %%~j==java set JAVAINSTALLED=1
if %%~j==openjdk set JAVAINSTALLED=1
)
rem BAT has no logical or, so we do it OLD SCHOOL! Oppan Redmond Style
set JAVAOK=true
if not defined JAVAINSTALLED set JAVAOK=false
if "%JAVAOK%"=="false" (
echo.
echo A Java JDK is not installed or can't be found.
if not "%JAVA_HOME%"=="" (
echo JAVA_HOME = "%JAVA_HOME%"
)
echo.
echo Please go to
echo http://www.oracle.com/technetwork/java/javase/downloads/index.html
echo and download a valid Java JDK and install before running play-java-starter-example.
echo.
echo If you think this message is in error, please check
echo your environment variables to see if "java.exe" and "javac.exe" are
echo available via JAVA_HOME or PATH.
echo.
if defined DOUBLECLICKED pause
exit /B 1
)
rem We use the value of the JAVA_OPTS environment variable if defined, rather than the config.
set _JAVA_OPTS=%JAVA_OPTS%
if "!_JAVA_OPTS!"=="" set _JAVA_OPTS=!CFG_OPTS!
rem We keep in _JAVA_PARAMS all -J-prefixed and -D-prefixed arguments
rem "-J" is stripped, "-D" is left as is, and everything is appended to JAVA_OPTS
set _JAVA_PARAMS=
set _APP_ARGS=
:param_loop
call set _PARAM1=%%1
set "_TEST_PARAM=%~1"
if ["!_PARAM1!"]==[""] goto param_afterloop
rem ignore arguments that do not start with '-'
if "%_TEST_PARAM:~0,1%"=="-" goto param_java_check
set _APP_ARGS=!_APP_ARGS! !_PARAM1!
shift
goto param_loop
:param_java_check
if "!_TEST_PARAM:~0,2!"=="-J" (
rem strip -J prefix
set _JAVA_PARAMS=!_JAVA_PARAMS! !_TEST_PARAM:~2!
shift
goto param_loop
)
if "!_TEST_PARAM:~0,2!"=="-D" (
rem test if this was double-quoted property "-Dprop=42"
for /F "delims== tokens=1,*" %%G in ("!_TEST_PARAM!") DO (
if not ["%%H"] == [""] (
set _JAVA_PARAMS=!_JAVA_PARAMS! !_PARAM1!
) else if [%2] neq [] (
rem it was a normal property: -Dprop=42 or -Drop="42"
call set _PARAM1=%%1=%%2
set _JAVA_PARAMS=!_JAVA_PARAMS! !_PARAM1!
shift
)
)
) else (
if "!_TEST_PARAM!"=="-main" (
call set CUSTOM_MAIN_CLASS=%%2
shift
) else (
set _APP_ARGS=!_APP_ARGS! !_PARAM1!
)
)
shift
goto param_loop
:param_afterloop
set _JAVA_OPTS=!_JAVA_OPTS! !_JAVA_PARAMS!
:run
set "APP_CLASSPATH=%APP_LIB_DIR%\..\conf\;%APP_LIB_DIR%\play-java-starter-example.play-java-starter-example-1.0-SNAPSHOT-sans-externalized.jar;%APP_LIB_DIR%\org.scala-lang.scala-library-2.12.2.jar;%APP_LIB_DIR%\com.typesafe.play.twirl-api_2.12-1.3.3.jar;%APP_LIB_DIR%\org.scala-lang.modules.scala-xml_2.12-1.0.6.jar;%APP_LIB_DIR%\com.typesafe.play.play-server_2.12-2.6.2.jar;%APP_LIB_DIR%\com.typesafe.play.play_2.12-2.6.2.jar;%APP_LIB_DIR%\com.typesafe.play.build-link-2.6.2.jar;%APP_LIB_DIR%\com.typesafe.play.play-exceptions-2.6.2.jar;%APP_LIB_DIR%\com.typesafe.play.play-netty-utils-2.6.2.jar;%APP_LIB_DIR%\org.slf4j.slf4j-api-1.7.25.jar;%APP_LIB_DIR%\org.slf4j.jul-to-slf4j-1.7.25.jar;%APP_LIB_DIR%\org.slf4j.jcl-over-slf4j-1.7.25.jar;%APP_LIB_DIR%\com.typesafe.play.play-streams_2.12-2.6.2.jar;%APP_LIB_DIR%\org.reactivestreams.reactive-streams-1.0.0.jar;%APP_LIB_DIR%\com.typesafe.akka.akka-stream_2.12-2.5.3.jar;%APP_LIB_DIR%\com.typesafe.akka.akka-actor_2.12-2.5.3.jar;%APP_LIB_DIR%\com.typesafe.config-1.3.1.jar;%APP_LIB_DIR%\org.scala-lang.modules.scala-java8-compat_2.12-0.8.0.jar;%APP_LIB_DIR%\com.typesafe.ssl-config-core_2.12-0.2.1.jar;%APP_LIB_DIR%\org.scala-lang.modules.scala-parser-combinators_2.12-1.0.6.jar;%APP_LIB_DIR%\com.typesafe.akka.akka-slf4j_2.12-2.5.3.jar;%APP_LIB_DIR%\com.fasterxml.jackson.core.jackson-core-2.8.9.jar;%APP_LIB_DIR%\com.fasterxml.jackson.core.jackson-annotations-2.8.9.jar;%APP_LIB_DIR%\com.fasterxml.jackson.core.jackson-databind-2.8.9.jar;%APP_LIB_DIR%\com.fasterxml.jackson.datatype.jackson-datatype-jdk8-2.8.9.jar;%APP_LIB_DIR%\com.fasterxml.jackson.datatype.jackson-datatype-jsr310-2.8.9.jar;%APP_LIB_DIR%\commons-codec.commons-codec-1.10.jar;%APP_LIB_DIR%\com.typesafe.play.play-json_2.12-2.6.2.jar;%APP_LIB_DIR%\com.typesafe.play.play-functional_2.12-2.6.2.jar;%APP_LIB_DIR%\org.scala-lang.scala-reflect-2.12.2.jar;%APP_LIB_DIR%\org.typelevel.macro-compat_2.12-1.1.1.jar;%APP_LIB_DIR%\joda-time.joda-time-2.9.9.jar;%APP_LIB_DIR%\com.google.guava.guava-22.0.jar;%APP_LIB_DIR%\com.google.code.findbugs.jsr305-1.3.9.jar;%APP_LIB_DIR%\com.google.errorprone.error_prone_annotations-2.0.18.jar;%APP_LIB_DIR%\com.google.j2objc.j2objc-annotations-1.1.jar;%APP_LIB_DIR%\org.codehaus.mojo.animal-sniffer-annotations-1.14.jar;%APP_LIB_DIR%\io.jsonwebtoken.jjwt-0.7.0.jar;%APP_LIB_DIR%\org.apache.commons.commons-lang3-3.6.jar;%APP_LIB_DIR%\javax.transaction.jta-1.1.jar;%APP_LIB_DIR%\javax.inject.javax.inject-1.jar;%APP_LIB_DIR%\com.typesafe.play.play-java-forms_2.12-2.6.2.jar;%APP_LIB_DIR%\com.typesafe.play.play-java_2.12-2.6.2.jar;%APP_LIB_DIR%\org.reflections.reflections-0.9.11.jar;%APP_LIB_DIR%\org.javassist.javassist-3.21.0-GA.jar;%APP_LIB_DIR%\net.jodah.typetools-0.5.0.jar;%APP_LIB_DIR%\org.hibernate.hibernate-validator-5.4.1.Final.jar;%APP_LIB_DIR%\javax.validation.validation-api-1.1.0.Final.jar;%APP_LIB_DIR%\org.jboss.logging.jboss-logging-3.3.0.Final.jar;%APP_LIB_DIR%\com.fasterxml.classmate-1.3.1.jar;%APP_LIB_DIR%\org.springframework.spring-context-4.3.9.RELEASE.jar;%APP_LIB_DIR%\org.springframework.spring-core-4.3.9.RELEASE.jar;%APP_LIB_DIR%\org.springframework.spring-beans-4.3.9.RELEASE.jar;%APP_LIB_DIR%\com.typesafe.play.filters-helpers_2.12-2.6.2.jar;%APP_LIB_DIR%\com.typesafe.play.play-logback_2.12-2.6.2.jar;%APP_LIB_DIR%\ch.qos.logback.logback-classic-1.2.3.jar;%APP_LIB_DIR%\ch.qos.logback.logback-core-1.2.3.jar;%APP_LIB_DIR%\com.typesafe.play.play-akka-http-server_2.12-2.6.2.jar;%APP_LIB_DIR%\com.typesafe.akka.akka-http-core_2.12-10.0.9.jar;%APP_LIB_DIR%\com.typesafe.akka.akka-parsing_2.12-10.0.9.jar;%APP_LIB_DIR%\com.typesafe.play.play-guice_2.12-2.6.2.jar;%APP_LIB_DIR%\com.google.inject.guice-4.1.0.jar;%APP_LIB_DIR%\aopalliance.aopalliance-1.0.jar;%APP_LIB_DIR%\com.google.inject.extensions.guice-assistedinject-4.1.0.jar;%APP_LIB_DIR%\com.h2database.h2-1.4.194.jar;%APP_LIB_DIR%\play-java-starter-example.play-java-starter-example-1.0-SNAPSHOT-assets.jar"
set "APP_MAIN_CLASS=play.core.server.ProdServerStart"
if defined CUSTOM_MAIN_CLASS (
set MAIN_CLASS=!CUSTOM_MAIN_CLASS!
) else (
set MAIN_CLASS=!APP_MAIN_CLASS!
)
rem Call the application and pass all arguments unchanged.
"%_JAVACMD%" !_JAVA_OPTS! !PLAY_JAVA_STARTER_EXAMPLE_OPTS! -cp "%APP_CLASSPATH%" %MAIN_CLASS% !_APP_ARGS!
#endlocal
:end
exit /B %ERRORLEVEL%
I figured it out.
Here are the steps:
I added the plugin play2war in project/plugins.sbt:
addSbtPlugin("com.github.play2war" % "play2-war-plugin" % "1.4.0")
add in build.sbt
import com.github.play2war.plugin._
libraryDependencies ++= Seq( "com.github.play2war" % "play2-war_2.9.1" % "0.8.2" )
Play2WarPlugin.play2WarSettings
Play2WarKeys.servletVersion := "3.1"
execute command sbt war
Except the war generated is quit strange, it contains only jar files, is it normal ?
I'm trying to create a CSV with fullpath\filename, file owner and last write access (modification date) of all txt and html files from all hard drives of a data server.
Here's what I got so far:
set pgm=%~n0
set log=%~dpn0.log
set host=%COMPUTERNAME%
set csv=%host%.csv
set dir=D:\BME
if not exist "%csv%" type nul>"%csv%"
for /f "delims=;" %%a in ('dir /b/s %dir%\*.txt, %dir%\*.html') do (
>>%csv% echo "%%a"
)
That outputs the path + filename of all found txt and html files of a certain folder in a CSV. I tried this command to get the hard drives:
wmic logicaldisk where drivetype=3 get caption
But I can't get my head around how to store that in a variable or file and loop through it and also retrieve the owner and last modification date and put it into a new column of the csv file.
I can't get my head around how to store that in a variable
Use the following batch file.
GetDrives.cmd:
#echo off
setlocal enabledelayedexpansion
rem skip=1 to remove the header
rem findstr to remove blank lines
for /f "skip=1" %%d in ('wmic logicaldisk where drivetype^=3 get caption ^| findstr /r /v "^$"') do (
set _drive=%%d
echo !_drive!
)
endlocal
Notes:
Be careful when using drivetype=3 as I have a removable drive of type 3. In the below output C: is a fixed hard disk and F: is a removable external USB drive.
Replace echo !_drive! as appropriate with a modified version of your existing code.
Example Output:
F:\test>GetDrives
C:
F:
F:\test>
Further Reading
An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
enabledelayedexpansion - Delayed Expansion will cause variables to be expanded at execution time rather than at parse time.
for /f - Loop command against the results of another command.
wmic - Windows Management Instrumentation Command.
DavidPostill answered how-to store wmic logicaldisk … output in a variable;
to retrieve file last modification date: use echo "%%a","%%~ta" in your script using %~t Parameter Extension;
to retrieve file owner: echo "%%a","%%~ta","!_owner!" where _owner variable comes from getRealOwner subroutine based on modified schletti2000's answer Get ownership information from command line by using wmic.
The script:
#ECHO OFF
SETLOCAL EnableExtensions DisableDelayedExpansion
set "pgm=%~n0"
set "log=%~dpn0.log"
set "host=%COMPUTERNAME%"
set "csv=%host%.csv"
set "dir=D:\BME"
set "dirmask=%dir%\*.txt, %dir%\*.html"
rem if not exist "%csv%" type nul>"%csv%"
>"%csv%" (
for /f "delims=;" %%a in ('dir /b/s %dirmask% 2^>NUL') do (
set "_fFullPath=%%~a"
set "_fLastWrite=%%~ta"
set "_fOwner="
call :getRealOwner
SETLOCAL EnableDelayedExpansion
echo "!_fFullPath!","!_fOwner!","!_fLastWrite!"
ENDLOCAL
)
)
)
type "%csv%"
goto :continue
:getRealOwner
SET "ESCAPED=%_fFullPath:\=\\%"
SET "UNDELIMITED="
for /F "skip=2 delims=" %%g in ('
wmic path Win32_LogicalFileSecuritySetting where Path^="%ESCAPED%" ^
ASSOC /RESULTROLE:Owner /ASSOCCLASS:Win32_LogicalFileOwner ^
/RESULTCLASS:Win32_SID 2^>NUL
') do (
SET "UNDELIMITED=%%g"
call :process_wmioutput
)
if NOT defined UNDELIMITED set "_fOwner=???"
exit /B
:process_wmioutput
SET "DELIMITED=%UNDELIMITED: =•%"
FOR /F "delims=• tokens=10,12" %%G in ("%DELIMITED%") DO set "_fOwner=%%H\%%G"
exit /B
:continue
I used next settings to demonstrate various output:
set "dir=D:"
set "dirmask=%dir%\loc*.vbs %dir%\bcd*.log %dir%\act*.xsl %dir%\diag*.xml %dir%\chec*.csv"
Output - non-privileged cmd window:
==> D:\bat\SO\39034430.bat
"D:\odds and ends\tempx\links\testDJ\LocUsers.vbs","mypc\user","25.12.2014 00:13"
"D:\tempWin\ActivityLog.xsl","NT AUTHORITY\SYSTEM","24.02.2016 13:12"
"D:\tempWin\CompatTelemetryLogs\diagerr.xml","???","12.08.2015 03:17"
"D:\tempWin\CompatTelemetryLogs\diagwrn.xml","???","12.08.2015 03:17"
"D:\test\check_acl.csv","BUILTIN\Administrators","06.03.2016 14:28"
Output - privileged (run as administrator) cmd window:
=ADMIN=> D:\bat\SO\39034430.bat
"D:\odds and ends\tempx\links\testDJ\LocUsers.vbs","mypc\user","25.12.2014 00:13"
"D:\tempWin\ActivityLog.xsl","NT AUTHORITY\SYSTEM","24.02.2016 13:12"
"D:\tempWin\CompatTelemetryLogs\diagerr.xml","NT AUTHORITY\SYSTEM","12.08.2015 03:17"
"D:\tempWin\CompatTelemetryLogs\diagwrn.xml","NT AUTHORITY\SYSTEM","12.08.2015 03:17"
"D:\test\check_acl.csv","BUILTIN\Administrators","06.03.2016 14:28"