I'm programming for an embedded device with a NVIDIA Tegra 2 running Windows Embedded Compact 7. My development environment is Microsoft Visual Studio 2008. The boost library and especially the boost-asio package seems to be very helpfull for my needs. Unfortunately I was not able to find a good guide on how to get boost running on Windows Embedded Compact 7. I'd prefere to get .lib files which I can link statically into my application.
It appears that the documentation on this process is sparse, because it requires non-trivial updates to the build process to get working with Windows CE. The most comprehensive tutorial to this problem appears to be here.
Since you explicitly tagged this boost-asio, I also looked into that component of Boost specifically. Here's a thread from the Boost mailing list that covers this library in detail, including potential failure cases you may experience, JAM file modifications, and a batch file to help you with the build.*
For those reading this: please share your experiences once you get this working. Despite various concerns that Boost is too memory-heavy for embedded applications, Boost provides the ability to use separate packages to meet your needs. I expect other users on SO will be very interested in your experiences getting this working.
* Because people have been expressing problems with the referenced batch file disappearing when Nabble links expire, here's a pastedump for posterity:
#SET VCINSTALLDIR=%VS9INSTALLDIR%\VC
#if "%VS9INSTALLDIR%"=="" goto error_no_VSINSTALLDIR
#if "%VCINSTALLDIR%"=="" goto error_no_VCINSTALLDIR
#echo Setting environment for using Microsoft Visual Studio 2008 tools for WM5.
#set TARGETCPU=X86
#call :GetWindowsSdkDir
#if not "%WindowsSdkDir%" == "" (
set "PATH=%WindowsSdkDir%bin;%PATH%"
)
#rem
#rem Root of Visual Studio IDE installed files.
#rem
#set DevEnvDir=%VS9INSTALLDIR%\Common7\IDE
#set PATH=%VCINSTALLDIR%\CE\bin\x86_arm;%VCINSTALLDIR%\bin;%VS9INSTALLDIR%\Common7\Tools;%DevEnvDir%;%VS9INSTALLDIR%\Common\Tools;%VS9INSTALLDIR%\Common\IDE;%VS9INSTALLDIR%;%PATH%
#set INCLUDE=%STLPORT_PATH%\STLPort-5.2.1\stlport;%VCINSTALLDIR%\ce\include;%CETOOLS%\Windows Mobile 5.0 Pocket PC SDK\include\ARMV4I;%CETOOLS%\Windows Mobile 5.0 Pocket PC SDK\include;%VCINSTALLDIR%\ce\atlmfc\include
#set LIB=%STLPORT_PATH%\STLPort-5.2.1\lib\evc9-arm;%CETOOLS%\Windows Mobile 5.0 Pocket PC SDK\lib\ARMV4I;%VCINSTALLDIR%\ce\ATLMFC\LIB\ARMV4I;%VCINSTALLDIR%\ce\LIB\ARMV4I
#set LIBPATH=
#goto end
:GetWindowsSdkDir
#call :GetWindowsSdkDirHelper HKLM > nul 2>&1
#if errorlevel 1 call :GetWindowsSdkDirHelper HKCU > nul 2>&1
#if errorlevel 1 set WindowsSdkDir=%VCINSTALLDIR%\PlatformSDK\
#exit /B 0
:GetWindowsSdkDirHelper
#for /F "tokens=1,2*" %%i in ('reg query "%1\SOFTWARE\Microsoft\Microsoft SDKs\Windows" /v "CurrentInstallFolder"') DO (
if "%%i"=="CurrentInstallFolder" (
SET "WindowsSdkDir=%%k"
)
)
#if "%WindowsSdkDir%"=="" exit /B 1
#exit /B 0
:error_no_VSINSTALLDIR
#echo ERROR: VS9INSTALLDIR variable is not set.
#goto end
:error_no_VCINSTALLDIR
#echo ERROR: VCINSTALLDIR variable is not set.
#goto end
:end
#SET VCINSTALLDIR=%VS9INSTALLDIR%\VC
#SET FrameworkDir=C:\WINDOWS\Microsoft.NET\Framework
#SET FrameworkVersion=v2.0.50727
#SET Framework35Version=v3.5
#if "%VS9INSTALLDIR%"=="" goto error_no_VSINSTALLDIR
#if "%VCINSTALLDIR%"=="" goto error_no_VCINSTALLDIR
#echo Setting environment for using Microsoft Visual Studio 2008 x86 tools with STLport-5.2.1.
#call :GetWindowsSdkDir
#if not "%WindowsSdkDir%" == "" (
set "PATH=%WindowsSdkDir%bin;%PATH%"
set "INCLUDE=%WindowsSdkDir%include;%INCLUDE%"
set "LIB=%WindowsSdkDir%lib;%LIB%"
)
#rem
#rem Root of Visual Studio IDE installed files.
#rem
#set DevEnvDir=%VS9INSTALLDIR%\Common7\IDE
#set PATH=%DevEnvDir%;%VCINSTALLDIR%\BIN;%VS9INSTALLDIR%\Common7\Tools;%FrameworkDir%\%Framework35Version%;%FrameworkDir%\%FrameworkVersion%;%VCINSTALLDIR%\VCPackages;%PATH%
#set INCLUDE=%STLPORT_PATH%\STLport-5.2.1\stlport;%VCINSTALLDIR%\ATLMFC\INCLUDE;%VCINSTALLDIR%\INCLUDE;%INCLUDE%
#set LIB=%STLPORT_PATH%\STLport-5.2.1\lib\vc9;%VCINSTALLDIR%\ATLMFC\LIB;%VCINSTALLDIR%\LIB;%LIB%
#set LIBPATH=%FrameworkDir%\%Framework35Version%;%FrameworkDir%\%FrameworkVersion%;%VCINSTALLDIR%\ATLMFC\LIB;%VCINSTALLDIR%\LIB;%LIBPATH%
#goto end
:GetWindowsSdkDir
#call :GetWindowsSdkDirHelper HKLM > nul 2>&1
#if errorlevel 1 call :GetWindowsSdkDirHelper HKCU > nul 2>&1
#if errorlevel 1 set WindowsSdkDir=%VCINSTALLDIR%\PlatformSDK\
#exit /B 0
:GetWindowsSdkDirHelper
#for /F "tokens=1,2*" %%i in ('reg query "%1\SOFTWARE\Microsoft\Microsoft SDKs\Windows" /v "CurrentInstallFolder"') DO (
if "%%i"=="CurrentInstallFolder" (
SET "WindowsSdkDir=%%k"
)
)
#if "%WindowsSdkDir%"=="" exit /B 1
#exit /B 0
:error_no_VSINSTALLDIR
#echo ERROR: VSINSTALLDIR variable is not set.
#goto end
:error_no_VCINSTALLDIR
#echo ERROR: VCINSTALLDIR variable is not set.
#goto end
:end
Related
I need to find the specific location of java 64-bit on a windows machine. I thought about using where java to find all possible locations. In the next step I would need to isolate the proper location which starts with: C:\Program Files\Java\... and then execute the command as following:
cmd /K %var% -jar %~dp0XYZ.jar
Is this the proper way to find the java path which might change over time? If yes, how can I get the path from where into a variable?
For the output of where assume this:
C:\Program Files (x86)\Common Files\Oracle\Java\javapath\java.exe
C:\Program Files\Java\jdk1.8.0_144\bin\java.exe
C:\Program Files\Java\jdk1.8.0_144\jre\bin\java.exe
It wouldn't matter if it takes second or third result, as both are 64 bit in this case. But as I can't guarantee that output, the only way to identify the 64-bit version is with C:\Program Files\Java\
The following bat script (commented for explanation) should do the trick:
#ECHO OFF
rem SETLOCAL EnableExtensions DisableDelayedExpansion
set "_flagexe64=:\Program Files\Java\"
set "_javaexe64="
for /f "delims=" %%G in ('where java.exe') do (
rem next two lines for debugging only
echo checking "%%~G"
"%%~G" -version
if not defined _javaexe64 (
set "_javaexe64=%%~G"
call :check64
)
)
rem final check
if not defined _javaexe64 (
1>&2 echo sorry, no java.exe found under "%_flagexe64%"
goto :eof
)
rem java.exe found:
echo "%_javaexe64%"
goto :eof
:check64
call set "_aux=%%_javaexe64:%_flagexe64%=%%"
if "%_aux%" == "%_javaexe64%" set "_javaexe64="
goto :eof
I'd like to remove the last character off a large file. The restrictions are that:
the file has to be modified in-situ, without using the disk space required for a similar second file
it's a windows machine
I cannot copy any compiled code onto the machine so I cannot create a small c# program of c++ program to manipulate the file
this also means any non-native scripting is not available, like python.
As far as I know, this limits me to bat, VB (or JScript) but it does not look like there is a viable option in these. VB requires a TextStream to be created from a systemfile object, but then this stream I believe must be saved elsewhere, using diskspace.
Is there a way to do this simply?
Following the idea from Noodles (of course you need to have some .net framework version installed), you can try this
(save as trim.cmd and call as trim.cmd "fileToTrim.dat")
#if (#this==#isBatch) #then
#echo off
setlocal enableextensions disabledelayedexpansion
rem check arguments
set "fileToTrim=%~1"
if not exist "%fileToTrim%" goto :eof
rem search for a valid framework version
set "frameworks=%SystemRoot%\Microsoft.NET\Framework"
set "jsc="
for /f "tokens=* delims=" %%a in (
'dir /b /a:d /o:-n "%frameworks%\v*"'
) do if not defined jsc if exist "%frameworks%\%%a\jsc.exe" set "jsc=%frameworks%\%%a\jsc.exe"
if not defined jsc goto :eof
set "executable=%~dpn0.%random%.exe"
%jsc% /nologo /out:"%executable%" "%~f0"
if exist "%executable%" (
"%executable%" "%fileToTrim%"
del "%executable%" >nul 2>nul
)
endlocal
exit /b 0
#end
import System;
import System.IO;
var arguments:String[] = Environment.GetCommandLineArgs();
if (arguments.length > 1) {
var fi:FileInfo = new FileInfo(arguments[1]);
var fs:FileStream = fi.Open(FileMode.Open);
fs.SetLength (
Math.max(0, fi.Length - 1)
);
fs.Close();
};
This is far from efficient, the jscript code is compiled each time. Better directly write the program, compile and use. But just as an example ...
As our office upgrades to Window 7, I have been tasked to update the loginscript to work with Windows 7. The creators of said script are long gone, and I am not a batch file expert.
What I am trying to do is determine the OS. As I do some network administration duties, I need to be able to log on to a server without running the login script whereas I will need to the login script to run if I log into a Windows XP or Windows 7 computer.
I found I couldn't use the VER command as Windows 7 and Windows Server 2008 return the exact same results.
This is what I have:
if exist %loginscriptdir%\sysinfo.txt goto setver
if not exist %loginscriptdir%\sysinfo.txt wmic os get name /value > %loginscriptdir%\sysinfo.txt
type %loginscriptdir%\sysinfo.txt > %loginscriptdir%\sysinfo1.txt
:setver
set WinVer=Unknown
set errorlevel=0
If %WinVer% == "Unknown" (
findstr /c:"Windows XP Professional" %loginscriptdir%\sysinfo1.txt
if %errorlevel%==1 set WinVer=XP
) else (
findstr /c:"Windows 7 Enterprise" %loginscriptdir%\sysinfo1.txt
if %errorlevel%==1 set WinVer=Win7
)
set result=false
if %WinVer% == "XP" set result=true
if %WinVer% == "Win7" set result=true
if "%result%" == "false" (
goto skipicon1
Throughout the script, I wrote in breaks to find the values. Example:
REM -----
ECHO "%WinVer%"
ECHO "%result%"
ECHO "%errorlevel%"
ECHO Press any key to continue 4.
pause>null
REM -----
The fourth break comes at the end of the script I pasted above. These are the results:
"Unknown"
"false"
"0"
Press any key to continue 4.
Here you go. This is the best way I've found to get the OS accurately from win2kpro-winserver2k10. It also tells if it's 32/64 bit and what sp is installed but you don't have to. Just check %cap% in this example.
#echo off
setlocal
call :GetOS cap bit sp
echo %cap%%bit% (%sp%)
exit /b
:GetOS caption servicepack
setlocal
set arc=%PROCESSOR_ARCHITECTURE%
set key="HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
for /f "tokens=3*" %%a in (
'reg query %key%^|findstr /i ProductName') do set cap=%%a %%b
for /f "tokens=3*" %%a in (
'reg query %key%^|findstr /i CSDVersion') do set sp=%%a %%b
endlocal & set %1=%cap% & set %2=%arc% & set %3=%sp%
exit /b
The issue with the code is the expansion of the %errorlevel% value. Since it is contained within a scope of parentheses, the value will not be updated till after the scope ends. Meaning that %errorlevel% will always equal its value when the scope began. To fix this you would have to use delayed expansion. setlocal enabledelayedexpansion and !errorlevel!. Here is a StackOverflow post about delayed expansion: Enable and Disable Delayed Expansion, what does it do?
You may just want to use the version detection method shown at ss64.com http://ss64.com/nt/ver.html
Here is the example from ss64.com but simplified:
#echo off
setlocal
:: Get windows Version
for /f "tokens=4,5,6 delims=[.] " %%A in ('ver') do (
set "Major=%%~A"
set "Minor=%%~B"
set "Build=%%~C"
)
if "%Major%.%Minor%"=="5.1" goto WinXP
if "%Major%.%Minor%"=="6.1" goto Win7
echo Unsupported Version Detected "%Major%.%Minor%"
goto End
:WinXP
echo Windows XP Detected
goto End
:Win7
echo Windows 7 or Server 2008 Detected
goto End
:End
endlocal
exit /b 0
How can we check if and which version of Visual Studio Shell is installed, from a batch script?
I understand we can check the existence of file/folder say under
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE
But I am looking for a more elegant and generic solution.
Any help?
Update to accepted answer:
Your answer is elegant and does the task. Since I was specifically checking for certain versions, I am using (after checking the link you provided):
#echo off
reg query "HKEY_CLASSES_ROOT\VisualStudio.DTE.10.0" >> nul 2>&1
if %ERRORLEVEL% NEQ 0 ( echo VS 2010 not installed ) else ( echo VS 2010 installed. )
reg query "HKEY_CLASSES_ROOT\VisualStudio.DTE.11.0" >> nul 2>&1
if %ERRORLEVEL% NEQ 0 ( echo VS 2012 not installed ) else ( echo VS 2012 installed. )
#echo off
for /d %%a in ("%programfiles%\Microsoft Visual Studio*") do (
for /f "tokens=3 delims=\" %%x in ("%%a") do echo %%x
)
pause >nul
If you need more details there are plenty of reg keys you can query to get more info but that would be much harder to extract the data you wanted from the keys and values.
Note: If you are running on x64 then you may need to add a check for %systemdrive%\Program Files (x86) depending on where VS is installed.
We have a Team City Build Server running and want to compile a Visual C++ project. So far this would be easy, since I've setup our Windows Build Agent with the Windows SDK, but we don't have a solution / project file.
The project files are instead created with CMake. CMake seems to be a little bit dumb (can't generate Solution when Visual Studio is not installed), but with some tricks, I could get it to do it. The solution can then be built with MSBuild.
And here comes the problem. For this to work automatically, I need to call the Windows SDK's SetEnv.cmd. And I can't seem to find it automatically. It's in the bin sub directory of the Windows SDK, but neither bin nor the root are in the path, and the %mssdk% environment variable is set by the SetEnv.cmd and is not available beforehand!
Adding the Windows SDK\bin dir to the PATH leads to SetEnv.cmd no longer working (exits with a message like The x86 compilers are not currently installed and Jump target Set_x86 not found.
The start menu link is calling the SetEnv.cmd with the Windows SDK dir as working directory instead. But if I add the root directory to the PATH, Bin\SetEnv.cmd is not available.
How can I find SetEnv.cmd automatically? Even setting an environment variable to the full path of the setenv.cmd doesn't work, and when I define %mssdk% as the sdk dir, then call %mssdk%\bin\SetEnv doesn't work as well. I also tried to define %mssdk%, then cd %mssdk%, then calling bin\SetEnv. Also compilers not found in all these cases. It also doesn't work if I manually cd to the root or bin dir on a command line and then call SetEnv.cmd...
The start menu link works fine though.
For the record, my solution for now, as strange as this is, is the following:
I created a MSBuild file that creates the solution file with CMake on the command line, then invokes the created solution with a MSBuild task. The MSBuild file can be easily built from TeamCity, though I needed some additional tricks to satisfy CMake's stupid looking for the compiler, though I won't invoke it thing. Not really satisfying, but it works.
My solution (sets %WindowsSdkPath%, so that SetEnv.cmd could be found under %WindowsSdkPath%Bin\):
#ECHO OFF
IF "%WindowsSdkVersion%"=="" (
CALL :SetWindowsSdkVersionHelper HKCU > nul 2>&1
IF ERRORLEVEL 1 CALL :SetWindowsSdkVersionHelper HKLM > nul 2>&1
IF ERRORLEVEL 1 GOTO ERROR_NOWSDK
)
CALL :SetWindowsSdkPathHelper > nul 2>&1
IF ERRORLEVEL 1 GOTO ERROR_NOWSDK
GOTO END
:SetWindowsSdkPathHelper
SET WindowsSdkPath=
FOR /F "tokens=1,2*" %%i in ('REG QUERY "HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows\%WindowsSdkVersion%" /V InstallationFolder') DO (
IF "%%i"=="InstallationFolder" (
SET "WindowsSdkPath=%%k"
)
)
IF "%WindowsSdkPath%"=="" EXIT /B 1
EXIT /B 0
:SetWindowsSdkVersion
CALL :GetWindowsSdkVersionHelper HKCU > nul 2>&1
IF ERRORLEVEL 1 CALL :GetWindowsSdkVersionHelper HKLM > nul 2>&1
IF ERRORLEVEL 1 EXIT /B 1
EXIT /B 0
:SetWindowsSdkVersionHelper
SET WindowsSdkVersion=
FOR /F "tokens=1,2*" %%i in ('REG QUERY "%1\SOFTWARE\Microsoft\Microsoft SDKs\Windows" /V "CurrentVersion"') DO (
IF "%%i"=="CurrentVersion" (
SET "WindowsSdkVersion=%%k"
)
)
IF "%WindowsSdkVersion%"=="" EXIT /B 1
EXIT /B 0
:ERROR_NOWSDK
ECHO The Windows SDK %WindowsSdkVersion% could not be found.
EXIT /B 1
:END
I was inspired for this by the SetEnv.cmd itself...
Mac, nice answer!
Now I would like to run msbuild with my project file. But before I should run SetEnv.Cmd - right?
So, here we go:
run_Macs_code.bat REM see above
call "%WindowsSdkPath%\bin\Setenv.cmd" /Release /x86 /xp
cd E:\client
msbuild client.proj
Now it's working :)