Simple batch file only fails when called from nmake.exe - windows

I have a simple batch file foo.bat:
#ECHO OFF
setlocal
echo %PATH%
WHERE /Q wsl.exe
if %ERRORLEVEL%% NEQ 0 (
echo No find wsl.exe %ERRORLEVEL%
exit /B
)
When I just run it in cmd or explicitly with cmd.exe /C foo.bat I have no problems. But if I put it into a nmake.exe Makefile:
all:
call foo.bat
.PHONY : all
and call it with nmake.exe /f Makefile all it will fail:
C:\cmder_mini\bin;C:\cmder_mini\vendor\bin;C:\cmder_mini\vendor\conemu-maximus5\ConEmu\Scripts;C:\cmder_mini\vendor\conemu-maximus5;C:\cmder_mini\vendor\conemu-maximus5\ConEmu;E:\VisualStudio\Common7\IDE\\Extensions\Microsoft\IntelliCode\CLI;E:\VisualStudio\VC\Tools\MSVC\14.30.30705\bin\HostX86\x86;E:\VisualStudio\Common7\IDE\VC\VCPackages;E:\VisualStudio\Common7\IDE\CommonExtensions\Microsoft\TestWindow;E:\VisualStudio\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer;E:\VisualStudio\MSBuild\Current\bin\Roslyn;E:\VisualStudio\Team Tools\Performance Tools;C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\\x86;C:\Program Files (x86)\Windows Kits\10\bin\\x86;E:\VisualStudio\\MSBuild\Current\Bin\amd64;C:\Windows\Microsoft.NET\Framework\v4.0.30319;E:\VisualStudio\Common7\IDE\;E:\VisualStudio\Common7\Tools\;C:\Program Files\CMake\bin;C:\Program Files\Python310\Scripts\;C:\Program Files\Python310\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Git\cmd;E:\home\nat\mulle-clang-project\13.0.0.1\bin;C:\Users\nat\AppData\Local\Microsoft\WindowsApps;E:\VisualStudio\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin;E:\VisualStudio\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja;E:\VisualStudio\Common7\IDE\VC\Linux\bin\ConnectionManagerExe;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\cmder_mini
No find wsl.exe 1
NMAKE : fatal error U1077: 'call' : return code '0x1'
When I diff the output of the working script and the failing nmake run I get
1,5d0
<
< Microsoft (R) Program Maintenance Utility Version 14.30.30709.0
< Copyright (C) Microsoft Corporation. All rights reserved.
<
< call foo.bat
7,9d1
< No find wsl.exe 1
< NMAKE : fatal error U1077: 'call' : return code '0x1'
< Stop.
So the PATH is identical. Once it finds "wsl.exe" in PATH and once it doesn't ? I have no clue here...

Related

Can a Windows batch file determine the file it opens

I have a file named USER_PREM_HOL_AMT.bat.
The code inside is:
set datename=%date% %username% %~n0
:CheckOS
IF EXIST "C:\Program Files\Microsoft Office\Office14\EXCEL.exe" (GOTO OFFICE2010) ELSE (GOTO OFFICE2013)
:OFFICE2010
ECHO %datename%>>"O:\Holiday.log"
START "" "C:\Program Files\Microsoft Office\Office14\EXCEL.exe" /e "file://///Log_files\Holiday.xlsm"
EXIT
GOTO END
This currently gives the log:
Tue 09/11/2018 7098703 USER_PREM_HOL_AMT
I want it to give me
Tue 09/11/2018 7098703 Holiday.xlsm
Is there a way to do this? Get the file name it's opening instead of its own name.
You can change the first line to specify the filename.
set "datename=%date% %username% Holiday.xlsm"

CGAL - building INSTALL .sln faild

I have a problem while compiling CGAL I followed the steps here : http://www.cse.msu.edu/~ytong/CGAL_installation.ppt
I'm using VS2013 , cgal 4.9.1 , BOOST 1.59.0 ,Qt5.7.1
but when I reach at building INSTALL .sln step it show the following error:
Error 1 error MSB3073: The command "setlocal
"C:\Program Files\CMake\bin\cmake.exe" -DBUILD_TYPE=Debug -P cmake_install.cmake
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd
:VCEnd" exited with code 1. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets 132 5 INSTALL
output message :
file INSTALL cannot find
1> "C:/dev/CGAL-4.9.1/build/bin/Debug/CGAL-vc120-mt-gd-4.9.1.dll".
1> Call Stack (most recent call first):
1> src/cmake_install.cmake:32 (include)
1> cmake_install.cmake:91 (include)
any help please?
Please use CGAL 4.12 and use installation instructions given on www.cgal.org

How can I find the latest Visual Studio Developer Command Prompt in a batch file?

I need to write a batch file to complete a pre-build step in Visual Studio. As part of it, I need to call the Visual Studio Developer Command Prompt.
I know that for VS2015, the developer command prompt is located in C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd.bat.
Unfortunately, our build server has a different version of VS. Is there a simple way to find the latest VSDevCmd.bat for all (or most) versions of Visual Studio in a batch file, so the pre-build step will work on both environments?
You should use vswhere provided by the Microsoft Visual Studio Installer. You copy vswhere.exe to a known location. The wiki has a description on how to start the developer command prompt:
#if not defined _echo echo off
for /f "usebackq delims=" %%i in (`vswhere.exe -prerelease -latest -property installationPath`) do (
if exist "%%i\Common7\Tools\vsdevcmd.bat" (
%comspec% /k "%%i\Common7\Tools\vsdevcmd.bat" %*
exit /b
)
)
rem Instance or command prompt not found
exit /b 2
The thing that I do for CI-CD machines is use vcvarsall for non 2017 machines and vsdevcmd for 2017 ones. Script snippet below:
rem vsvarsall.bat does not work if there are quoted paths on %PATH%
set path=%path:"=%
rem this will work for non VS 2017 build machines
if exist "c:\progra~2\Micros~1.0\vc\vcvarsall.bat" (
call c:\progra~2\Micros~1.0\vc\vcvarsall.bat && goto :SetVSEnvFinished
)
echo vcvarsall.bat not found, looking for vsdevcmd.bat
rem Find and run vsdevcmd.bat
set "VS_PATH=C:\Program Files (x86)\Microsoft Visual Studio\2017"
rem The 2017 folder will not be present in Visual Studio 2017 Preview machines (such as 15.8 preview)
if not exist "%VS_PATH%" (
set "VS_PATH=C:\Program Files (x86)\Microsoft Visual Studio"
)
if not exist "%VS_PATH%" (
echo "%VS_PATH%" not found. Is Visual Studio installed? && goto :ErrorExit
)
for /f "delims=" %%F in ('dir /b /s "%VS_PATH%\vsdevcmd.bat" 2^>nul') do set VSDEVCMD_PATH=%%F
echo ********Executing %VSDEVCMD_PATH%********
call "%VSDEVCMD_PATH%"
goto :SetVSEnvFinished
:ErrorExit
exit /b 1
:SetVSEnvFinished
So for non 2017 ones, it will execute vcvarsall.bat (which sets up the VS environment). For 2017 versions, it will search for vsdevcmd.bat (in specific folder to reduce search time) and run it.
Hope this helps.
I've managed to cobble together a batch file that looks at parameters, then at the filesystem to try to figure out what version of VSDevCmd should be used. $(DevEnvDir) is sometimes *Undefined*, so we need to check for that too.
Tested on VS2015 Professional, VS2017 Professional, and VS2017 Enterprise.
REM Usage in VS build event: call "$(SolutionDir)\find_vsdevcmd.bat" "$(DevEnvDir)"
SET vsversion=
REM Get Visual Studio version, either from command prompt, or newest on filesystem
if [%1] == [] (
if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\VsDevCmd.bat" (
SET vsversion="VS2017 Enterprise"
) else if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools\VsDevCmd.bat" (
SET vsversion="VS2017 Professional"
) else if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\VsDevCmd.bat" (
SET vsversion="VS2017 Community"
) else if exist "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd.bat" (
SET vsversion="VS2015"
) else if exist "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\VsDevCmd.bat" (
SET vsversion="VS2013"
) else goto :eof
) else if [%1] == ["*Undefined*"] (
if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\VsDevCmd.bat" (
SET vsversion="VS2017 Enterprise"
) else if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools\VsDevCmd.bat" (
SET vsversion="VS2017 Professional"
) else if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\VsDevCmd.bat" (
SET vsversion="VS2017 Community"
) else if exist "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd.bat" (
SET vsversion="VS2015"
) else if exist "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\VsDevCmd.bat" (
SET vsversion="VS2013"
) else goto :eof
) else (
if [%1] == ["C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\"] (
SET vsversion="VS2017 Enterprise"
) else if [%1] == ["C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\"] (
SET vsversion="VS2017 Professional"
) else if [%1] == ["C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\"] (
SET vsversion="VS2017 Community"
) else if [%1] == ["C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\" (
SET vsversion="VS2015"
) else if [%1] == ["C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\" (
SET vsversion="VS2013"
) else goto :eof
)
if %vsversion% == "VS2017 Enterprise" (
SET vsdevcmd="C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\VsDevCmd.bat"
ECHO VS2017 Enterprise
) else if %vsversion% == "VS2017 Professional" (
SET vsdevcmd="C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools\VsDevCmd.bat"
ECHO VS2017 Professional
) else if %vsversion% == "VS2017 Community" (
SET vsdevcmd="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\VsDevCmd.bat"
ECHO VS2017 Community
) else if %vsversion% == "VS2015" (
SET vsdevcmd="C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd.bat"
ECHO VS2015
) else if %vsversion% == "VS2013" (
SET vsdevcmd="C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\VsDevCmd.bat"
ECHO VS2013
) else goto :eof
call %vsdevcmd%

Generating an installer using CMake + CPack + Wix

Summary:
How to generate Wix installer with CMake/CPack?
Details:
I am trying to generate an installer out from a project that uses Wix, but apparently, cmake/cpack insist to use nsis, for example, from the repo https://github.com/ngladitz/cmake-wix-testsuite
I picked the first example "basic" folder with the following contents for CMakeLists.txt
add_executable(hw hw.cpp)
install(TARGETS hw DESTINATION bin)
install(FILES hw.cpp DESTINATION src)
set(CPACK_WIX_UPGRADE_GUID "F9AAAAE2-D6AF-4EA4-BF46-B3E265400CC7")
include(CPack)
After generating the cmake:
cd <basic-root-folder>
mkdir MY_BUILD
cd MY_BUILD
cmake ..
I tried to run the package.vcxproj generated with
msbuild package.vcxproj
and got the error
"C:\src\Samples\CPack\cmake-wix-testsuite-master\basic\MY_BUILD\PACKAGE.vcxproj
" (default target) (1) ->
(PostBuildEvent target) ->
EXEC : CPack error : Cannot find NSIS compiler makensis: likely it is not ins
talled, or not in your PATH [C:\src\Samples\CPack\cmake-wix-testsuite-master\ba
sic\MY_BUILD\PACKAGE.vcxproj]
So it looks like it insist in using the NSIS generator.
Simply add following line before include(CPack)
set(CPACK_GENERATOR WIX)
You can also do this:
cmake ..
cpack -G WIX
By default, CPack uses the NSIS Generator on Windows.
Ok, I found how
By specifying the CPack generator like
cmake -DCPACK_GENERATOR=WIX ..
Then running
msbuild package.vcxproj
Invokes wix like this extract from the log (and a bunch of .wixobj files)
PostBuildEvent:
setlocal
cd C:\src\Samples\CPack\cmake-wix-testsuite-master\basic\MY_BUILD.wix
if %errorlevel% neq 0 goto :cmEnd
C:
if %errorlevel% neq 0 goto :cmEnd
"C:\Program Files (x86)\CMake 3.1.3\bin\cpack.exe" -C Debug --config ./CPackC
onfig.cmake
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd
:VCEnd
CPack: Create package using WIX
CPack: Install projects
CPack: - Install project: Project
CPack: Create package
CPack: - package: C:/src/Samples/CPack/cmake-wix-testsuite-master/basic/MY_BU
ILD.wix/Project-0.1.1-win32.msi generated.
FinalizeBuildStatus:
Deleting file "Win32\Debug\PACKAGE\PACKAGE.tlog\unsuccessfulbuild".
Touching "Win32\Debug\PACKAGE\PACKAGE.tlog\PACKAGE.lastbuildstate".
Done Building Project "C:\src\Samples\CPack\cmake-wix-testsuite-master\basic\MY
_BUILD.wix\PACKAGE.vcxproj" (default targets).
Build succeeded.
0 Warning(s)
0 Error(s)
Also the .wix source files are generated at C:\src\Samples\CPack\cmake-wix-testsuite-master\basic\MY_BUILD.wix\\_CPack_Packages\win32\WIX
I found out about this arg (CPACK_GENERATOR) by inspecting CPackConfig.cmake generated by the original cmake.

batchfile is not running in prebuild event vs2013

I had a batch command that copies multiple files from source to destination
for %I in ( C:\Source\abc.txt C:\Source\cba.txt) do copy %I C:\Destination
if we give the command in buildevent->prebuild event ->commandline of visual studio 2013
Its throwing me the error
error MSB3073: The command "for %I in ( C:\Source\abc.txt C:\Source\cba.txt) do xcopy %I C:\Destination :VCEnd" exited with code 255.
If we run the command in command prompt its successfully copied.
Why this is throwing the error in vs 2013 ?
Thanks
Phani
Issue
From a quick search around, it would seem that error code 255 means that it is failing to find the file.
ILMerge - the command exited with code 255
Copy task, MSB3073, exit code 255
ERROR_EA_LIST_INCONSISTENT
255 (0xFF)
The extended attributes are inconsistent.
Resolution
Try using absolute paths "%~fI" in the command and the flag /Y to prevent copy prompts.
for %I in ("C:\Source\abc.txt" "C:\Source\cba.txt") do xcopy "%~fI" "C:\Destination" /Y
May also be experiencing file or directory prompt which can be resolved with echo d |
for %I in ("C:\Source\abc.txt" "C:\Source\cba.txt") do echo d | xcopy "%~fI" "C:\Destination" /Y

Resources