I think this is just simple and really googling around does give a lot of answers but not sure why it's not working for me.
Firstly without any ENV PATH = set, I can check that the PATH has a default value of
C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Users\ContainerAdministrator\AppData\Local\Microsoft\WindowsApps
I check that by simply running the image and use CMD echo %PATH%.
However with the following setting, all the default is gone letting the new value alone (looks really like that it cannot get the default value or simply that value is empty):
ENV PATH = "C:\Program Files\dotnet\:${PATH}"
Here are various attempts (not working):
#this even tries removing spaces around the =
#like some ones warned that could break the PATH
ENV PATH="C:\Program Files\dotnet:${PATH}"
ENV PATH = "C:\Program Files\dotnet\:$PATH"
ENV PATH = "C:\Program Files\dotnet:${PATH}"
ENV PATH = "C:\Program Files\dotnet:$PATH"
ENV PATH = "C:\Program Files\dotnet;${PATH}"
ENV PATH = "C:\Program Files\dotnet;$PATH"
ENV PATH = "C:\Program Files\dotnet;$env:PATH"
With one of the above setting, the PATH (checked by echo %PATH% when executing cmd on a running container) becomes just C:\Program Files\dotnet (maybe with some more characters appended for some cases).
Really I would like to bang my head against the wall for such a simple issue but has taken me hours. Really?
And here is the full dockerfile:
# escape=`
FROM microsoft/dotnet:2.1-sdk-nanoserver-1803 AS dotnet
FROM microsoft/dotnet-framework:4.7.2-runtime-windowsservercore-1803
ENV DOTNET_PATH="C:\Program Files\dotnet"
COPY --from=dotnet ${DOTNET_PATH} ${DOTNET_PATH}
ENV PATH = "C:\Program Files\dotnet\:${PATH}"
ENV ASPNETCORE_URLS=http://+:80 `
DOTNET_RUNNING_IN_CONTAINERS=true `
DOTNET_SKIP_FIRST_TIME_EXPERIENCE="true"
I hope someone here could point out what's wrong. Thanks!
RUN setx /M PATH "C:\Program Files\dotnet;%PATH%"
Related
I want to create a file in C drive while building docker image and using command as below
RUN mkdir "C:\Program Files\Microsoft Passport RPS"
but it throws error:
Step 6/6 : RUN mkdir "C:\Program Files\Microsoft Passport RPS"
---> Running in ab58c6f2948d
[91mmkdir : A positional parameter cannot be found that accepts argument 'Files\Microsoft'.
At line:1 char:76
+ ... e = 'SilentlyContinue'; mkdir C:\Program Files\Microsoft Passport RPS
[0m[91m+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[0m[91m + CategoryInfo : InvalidArgument: (:) [mkdir], ParentContainsErro
[0m[91m rRecordException
+ FullyQualifiedErrorId : PositionalParameterNotFound,mkdir
Tried above command with forward as well as back slash.
I have tried multiple other command as below:
ENV PATH_WITH_SPACE "C:/Program Files/Microsoft Passport RPS"
RUN mkdir $[PATH_WITH_SPACE]
RUN mkdir ["C:\Program Files\Microsoft Passport RPS"]
Can you please help me with appropriate command?
Came across same problem. None of the answers worked for me.
I finally got it working by escaping space with `
RUN mkdir "C:\Program` Files\Microsoft` Passport` RPS"
COPY . "C:\Program` Files\Microsoft` Passport` RPS"
Another approach is to use Shell, and declare escape explictly
While the JSON form is unambiguous and does not use the un-necessary cmd.exe, it does require more verbosity through double-quoting and escaping. The alternate mechanism is to use the SHELL instruction and the shell form, making a more natural syntax for Windows users, especially when combined with the escape parser directive
# escape=`
FROM microsoft/nanoserver
SHELL ["powershell","-command"]
RUN New-Item -ItemType Directory C:\Example
ADD Execute-MyCmdlet.ps1 c:\example\
RUN c:\example\Execute-MyCmdlet -sample 'hello world'
You have to escape the space, some like:
RUN mkdir "C:\Program Files\Microsoft\ Passport\ RPS"
Or using the JSON format:
RUN ["mkdir", "C:\\Program Files\\Microsoft\ Passport\ RPS"]
note: using JSON format is necessary to escape backslashes. This is particularly relevant on Windows where the backslash is the path separator.
We can use PowerShell command to create folder with spaces.
Try this:
RUN powershell -Command New-Item -Path 'C:\Program Files\Microsoft Passport RPS' -ItemType Directory
It Works !!!
I'd like to set a file's name to a variable in a batch file. I'm already pulling the file name by pulling the total path length. Is there a way I can parse the path to only give me back the file name?
The particular script that I use to pull the path looks like this:
for /f "delims=_" %%J IN ('forfiles /p "%%F" /m *.extension /c "cmd /c echo #path"')
DO start "Program" /D "c:\fullpath" /Wait program -r %%J
Also, if there's an easier way to pull the file name and put it into a variable I'm open to that as well.
I am using following code to append ";C:\Python27" to environment variable PATH..
#echo off
Setx Path "%PATH%;C:\Python27" -M
PAUSE
but if i run this batch file more than once, it is appending ";C:\Python27" many times that should not happen.
SO i have to check for ;C:\Python27 before appending it to PATH variable.
Is there any command for this purpose?
The following Powershell should do it:
$needPython = $env:path | select-string -NotMatch -SimpleMatch "c:\python27"
if ($needPython) {
[Environment]::SetEnvironmentVariable("tstpath", $env:path + ";c:\python27", "User")
}
You can change User to Machine or Process to set a machine or process level environment variable.
You can run this directly from a powershell prompt.
If you're running this from a dos command line use (you need the full path to your script or .\ if it's in the current directory):
powershell "& '.\myscript.ps1'"
I added
version.target = version.h
version.commands = bash generate-version.sh
QMAKE_EXTRA_TARGETS += version
PRE_TARGETDEPS += version.h
to the project, but it attempts to run "generate-version.sh" in destination directory:
make: Leaving directory `.../qqq-build-desktop'
make: Entering directory `.../qqq-build-desktop'
Makefile:236: warning: overriding commands for target `version.h'
Makefile:233: warning: ignoring old commands for target `version.h'
bash generate-version.sh
bash: generate-version.sh: No such file or directory
make: Leaving directory `.../qqq-build-desktop'
There is $$DESTDIR, but I don't see $$SRCDIR. How to refer to the project directory in qmake (or how to rewrite this)?
My first thought is to try to rewrite
version.commands = bash generate-version.sh
so as not to have to invoke a shell script. Perhaps you can combine all of the statements into one line:
version.commands = echo \'char VERSION[]=\"1.0\";\' > version.h && ls && echo Done
If you are stuck with invoking the script, probably PWD or OUT_PWD are what you are looking for. From the qmake Variable Reference
PWD
This variable contains the full path leading to the directory where the qmake project file (project.pro) is located.
OUT_PWD
This variable contains the full path leading to the directory where qmake places the generated Makefile.
The one caveat that is not mentioned in the documentation is that if you are doing a recursive qmake, PWD refers to where the top level .pro file was read from. Thus if you run qmake -r from {proj-root}, when sub/sub/sub/dir-proj.pro is finally read in, PWD will still point to {proj-root}.
Assuming that generate-version.sh is in the same directory as your top level .pro file, you might try:
version.commands = bash $$PWD/generate-version.sh
I found a better and cleaner solution
version.target = version.h
version.commands = bash ${QMAKE_VAR__PRO_FILE_PWD_}/generate-version.sh
QMAKE_EXTRA_TARGETS += version
The variable _PRO_FILE_PWD_ is documented since qt 4.5 and contains the path to the directory containing the project file in use (Contains the .pro file)
But to access this variable for QMAKE_EXTRA_TARGETS, QMAKE_VAR_ must be appended.
PWD
Specifies the full path leading to the directory containing the
current file being parsed. This can be useful to refer to files within
the source tree when writing project files to support shadow builds.
I use (Linux and g++)
DEFINES += SVN_VERSION=\\\"\""`svnversion $$PWD`\""\\\"
DEFINES += COMPILE_DATE=\\\"\""`date`\""\\\"
DEFINES += SW_VERSION=\\\"\"0.5\"\\\"
which defines the macro SVNVERSON to be the svn version.
To access it from C++:
QString svnVersion = SVN_VERSION;
QString swVersion = SW_VERSION;
Explanation: On the shell I want to see this call:
-DSVN_VERSION=\""`svnversion /path/to/my/source`"\"
As you see some escapes are necessary on shell level. In the .pro-file it then has to be escaped twice.
This works and is easy to understand.
version.commands = ( cd $${PWD}; generate-version.sh )
I've been using sbox with a Make-based codebase with no problems. Now
I'm using a scons-based codebase, and am getting some odd problems.
It seems that within scratchbox, scons can't find g++. For example, it
attempts to execute things like:
o hello hello.c
When it should be doing:
g++ -o hello hello.c
So presumably its g++ string variable is empty. g++ is present and in
the PATH - "which g++" produces /scratchbox/compilers/bin/g++.
The same source builds fine outside of scratchbox, so it shouldn't be
a problem with scons or the codebase. There are no special environment
variables set outside of scratchbox when it works.
If I symbolically link /usr/bin/g++ to /scratchbox/compilers/bin/g++,
it gets a bit further (produces the correct-looking g++ commands) but
then upon executing them produces:
sb_gcc_wrapper (g++):
/scratchbox/compilers/arm-linux-cs2007q3-51sb3/bin/sbox-arm-none-linux-gnueabi-g++:
No such file or directory
The file listed is present.
PATH contains /scratchbox/compilers/bin, SBOX_REDIRECT_FROM_DIRS contains /usr/bin and SBOX_REDIRECT_TO_DIRS contains /scratchbox/compilers/bin, so I think it should be able to find it.
Any suggestions would be appreciated!
Thanks,
Ray
Edit: Perhaps related - it also can't find pkg-config unless I prepend the full path within the scons file
scons does not propagate the PATH environment variable, so testing e.g. 'which g++' doesn't help much.
Either set the compilers directly, e.g.
env['CXX'] = '/scratchbox/compilers/bin/g++'
Build your own explicit PATH
path = ['/scratchbox/compilers/bin/','/bin', '/usr/bin', '/sbin','/usr/sbin']
env = Environment(ENV = {'PATH' : path})
Or use the PATH env variable from your shell
import os
env = Environment(ENV = {'PATH' : os.environ['PATH']})