Rectangle 27 11

2. Setting the PATH explicitly using two COMMAND parameters

While still doing my research in order to ask the question properly, I have found three solutions. Considering how hard it was to find this information, I decided to post the question and answer here anyway.

There is a special variable dedicated to solving this exact problem CMAKE_MSVCIDE_RUN_PATH. If set, it results in a line like this being added to the custom build step script:

set PATH=<CMAKE_MSVCIDE_RUN_PATH>;%PATH%

So all that's needed then is something like this at a good place:

set(CMAKE_MSVCIDE_RUN_PATH ${LibFoo_RUNTIME_LIBRARY_DIRS})

I have originally noticed this variable only in CMake sources, because it used to be undocumented until CMake 3.10. So you might not be able to find it in documentation for older versions of CMake, but don't worry, it's been supported since 2006.

Advantages: Can be enabled at one central place No change at all in any of the add_custom_command() commands elsewhere is needed Only the path itself is set, no batch commands need to be written explicitly The obvious choice with clear name and intent

Disadvantages: Global for the whole CMake project and all custom commands Works with the "Visual Studio 9 2008" and above generators only

The script being generated for the custom build step in Visual Studio contains some prologue, then the commands themselves and then some epilogue. Wouldn't it be possible to simply add set PATH=... before the real command through another COMMAND parameter?

COMMAND Specify the command-line(s) to execute at build time. If more than one COMMAND is specified they will be executed in order, but not necessarily composed into a stateful shell or batch script.

So no, that's not guaranteed to be possible. But the Visual Studio project generator actually does it like this, i.e. the individual commands are just appended one after another, so the following does the job:

add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/Table.h"
                   COMMAND set "PATH=${LibFoo_RUNTIME_LIBRARY_DIRS};%PATH%"
                   COMMAND TableGenerator "${CMAKE_CURRENT_BINARY_DIR}/Table.h"
                   DEPENDS TableGenerator)

Disadvantages: Relies on an undocumented behavior of the generator It's necessary to rewrite the whole command for Windows and keep both versions in sync Each custom command must be changed explicitly

add_custom_command()

To run a full script, use the configure_file() command or the file(GENERATE) command to create it, and then specify a COMMAND to launch it.

This is a bit messy because of the additional temporary files and commands:

file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/RunTableGenerator.cmd"
              CONTENT "set PATH=${LibFoo_RUNTIME_LIBRARY_DIRS};%PATH%
                       %1 ${CMAKE_CURRENT_BINARY_DIR}/Table.h")
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/Table.h"
                   COMMAND "${CMAKE_CURRENT_BINARY_DIR}/RunTableGenerator.cmd" "$<TARGET_FILE:TableGenerator>"
                   DEPENDS TableGenerator)

Notice the awkward way of sending the path to the executable as an argument. This is necessary because the script is writen once, but TableGenerator might be in different locations for different configurations (debug and release). If the generator expression was used directly in the content, a CMake error would be printed and the project would not build correctly for all but one configuration.

Advantages: The PATH can be changed for each custom command explicitly A fully documented and recommended solution

Disadvantages: Very noisy in the CMakefiles It's necessary to rewrite the whole command for Windows and keep both versions in sync Each custom command must be changed explicitly

I had personally settled on the solution #1 because it was clean and simple, even before it got properly documented and supported by CMake in version 3.10. It should be the best way forward for you as well, unless you need to do something even more special.

Unfortunatly, I didn't manage to make it work on my setup.... had to copy dll's with a post build custom_target. Where should the result of the CMAKE_MSVCIDE_RUN_PATH variable be seen ? I saw some lines appearing as CustomBuild in the vcxproj file... but unable to launch the debugger from VS and get the DLL loaded :/

I see. This question deals with CMake custom commands (e.g. you have blah.template in the project and it gets transformed through some preprocessor to blah.h as part of the compilation). You want to change DLL paths for running/debugging apps under VS, which is a different thing. You can avoid copying DLLs around by adding the path manually under "Project properties > Debugging > Environment" as e.g. Path=$(SolutionDir)external\somelib\bin;%Path%. Unfortunately automating that in CMake seems to be harder see gitlab.kitware.com/cmake/cmake/issues/8884 for more info.

Ok I wasn't sure about that, now it's clear. thanks !

visual studio - How to set runtime PATH for CMake custom command on Wi...

windows visual-studio dll path cmake
Rectangle 27 105

When setting Environmental Variables in Windows, I have gone wrong on many, many occasions. I thought I should share a few of my past mistakes here hoping that it might help someone. (These apply to all Environmental Variables, not just when setting Python Path)

  • Kill and reopen your shell window: Once you make a change to the ENVIRONMENTAL Variables, you have to restart the window you are testing it on.
  • NO SPACES when setting the Variables. Make sure that you are adding the ;C:\Python27 WITHOUT any spaces. (It is common to try C:\SomeOther; C:\Python27 That space () after the semicolon is not okay.)
  • USE A BACKWARD SLASH when spelling out your full path. You will see forward slashes when you try echo $PATH but only backward slashes have worked for me.

DO NOT ADD a final backslash

C:\Python27
C:\Python27\

The reason that I chose this answer is that most of the time the PATH get's broken because of one of these 4 things. The easy part is doing it correctly, the hard part is noticing when you did it incorrectly!

The command echo $path is only valid if you're running a bash shell under windows (e.g. MinGW). The windows command prompt command is echo %path%

Adding Python Path on Windows 7 - Stack Overflow

python windows python-2.7 path
Rectangle 27 105

When setting Environmental Variables in Windows, I have gone wrong on many, many occasions. I thought I should share a few of my past mistakes here hoping that it might help someone. (These apply to all Environmental Variables, not just when setting Python Path)

  • Kill and reopen your shell window: Once you make a change to the ENVIRONMENTAL Variables, you have to restart the window you are testing it on.
  • NO SPACES when setting the Variables. Make sure that you are adding the ;C:\Python27 WITHOUT any spaces. (It is common to try C:\SomeOther; C:\Python27 That space () after the semicolon is not okay.)
  • USE A BACKWARD SLASH when spelling out your full path. You will see forward slashes when you try echo $PATH but only backward slashes have worked for me.

DO NOT ADD a final backslash

C:\Python27
C:\Python27\

The reason that I chose this answer is that most of the time the PATH get's broken because of one of these 4 things. The easy part is doing it correctly, the hard part is noticing when you did it incorrectly!

The command echo $path is only valid if you're running a bash shell under windows (e.g. MinGW). The windows command prompt command is echo %path%

Adding Python Path on Windows 7 - Stack Overflow

python windows python-2.7 path
Rectangle 27 4

I installed node for windows. There is a node.js command prompt when I search for node.js in windows 7 start menu If you run this special command prompt, you can node anything in any location without setting up the path or copy node.exe everywhere.

How to run a hello.js file in Node.js on windows? - Stack Overflow

windows node.js
Rectangle 27 3

I installed node for windows. There is a node.js command prompt when I search for node.js in windows 7 start menu If you run this special command prompt, you can node anything in any location without setting up the path or copy node.exe everywhere.

How to run a hello.js file in Node.js on windows? - Stack Overflow

windows node.js
Rectangle 27 11

Although the current accepted answer works in the sense that the path variable gets permanently updated from the context of PowerShell, it doesn't actually update the environment variable stored in the windows registry. To achieve that you can obviously use PowerShell as well:

$oldPath=(Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).Path

$newPath=$oldPath+;C:\NewFolderToAddToTheList\

Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH Value $newPath

If you use PowerShell community extensions, the proper command to add a path to the environment variable path is:

Add-PathVariable "C:\NewFolderToAddToTheList" -Target Machine

Setting Windows PowerShell path variable - Stack Overflow

windows powershell
Rectangle 27 10

Although the current accepted answer works in the sense that the path variable gets permanently updated from the context of PowerShell, it doesn't actually update the environment variable stored in the windows registry. To achieve that you can obviously use PowerShell as well:

$oldPath=(Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).Path

$newPath=$oldPath+;C:\NewFolderToAddToTheList\

Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH Value $newPath

If you use PowerShell community extensions, the proper command to add a path to the environment variable path is:

Add-PathVariable "C:\NewFolderToAddToTheList" -Target Machine

Setting Windows PowerShell path variable - Stack Overflow

windows powershell
Rectangle 27 2

Most common mistake (particularly on Windows) is to forget setting up the path of "extension_dir" in the php.ini file. PHP by default assumes C:\php\ext, whereas many prefer to unzip PHP to C:\Program Files\PHP.

mysql - Windows + PHP 5.3.6 - Undefined function, mysql_connect? - Sta...

php mysql apache mysqli
Rectangle 27 16

The easier way to set the path in python is : click start> My Computer >Properties > Advanced System Settings > Environment Variables > second windows >

select Path > Edit > and then add ";C:\Python27\;C:\Python27\Scripts\"

python - How to add to the pythonpath in windows 7? - Stack Overflow

python windows environment-variables pythonpath
Rectangle 27 15

The easier way to set the path in python is : click start> My Computer >Properties > Advanced System Settings > Environment Variables > second windows >

select Path > Edit > and then add ";C:\Python27\;C:\Python27\Scripts\"

python - How to add to the pythonpath in windows 7? - Stack Overflow

python windows environment-variables pythonpath
Rectangle 27 15

The easier way to set the path in python is : click start> My Computer >Properties > Advanced System Settings > Environment Variables > second windows >

select Path > Edit > and then add ";C:\Python27\;C:\Python27\Scripts\"

python - How to add to the pythonpath in windows 7? - Stack Overflow

python windows environment-variables pythonpath
Rectangle 27 15

The easier way to set the path in python is : click start> My Computer >Properties > Advanced System Settings > Environment Variables > second windows >

select Path > Edit > and then add ";C:\Python27\;C:\Python27\Scripts\"

python - How to add to the pythonpath in windows 7? - Stack Overflow

python windows environment-variables pythonpath
Rectangle 27 8

In windows 8.1, setting the PATH Environment Variable to Git's bin directory didn't work for me. Instead, I had to use the cmd directory C:\Program Files (x86)\Git\cmd.

Command-line Git on Windows - Stack Overflow

windows git command-line
Rectangle 27 8

I had a similar problem setting it up in windows 10. My answer is windows specific (look at the answers for modifying path in bash for a linux or OSX solution)

The core problem I had was that npm's folder was not registered in the path. I originally tried changing this in cmd prompt.

setx path "%path%;%appdata$\npm"

Note that I used setx instead of set to ensure that the update to the environmental variable remains. Also note that it's a backslash.

This should work but for me it didn't because setx has a limit of only accepting 1024 characters... (yes it's nonsensical to me as well).

So try the above and if you get a warning like did about reaching the 1024 limit, then you can do the other way I ended up doing.

First while youre still in the console, type: echo %appdata%\npm ... this is your npm folder that you want to add to the path so add it to your clipboard.

You have to go into the registry and reach the following folder:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

Then append the 'Path' value with the npm folder path in your clipboard. Reboot to activate the new value and you should now be good to go.

>npm install -g gulp
>gulp

Yes!!! Finally! I have looked all over for something to help. Almost all of the answers say to install it globally and it should work. I've installed, uninstalled, reinstalled, cleared cache, etc. At last, this worked. Thank you!

@Josh, glad I could get you running. Setting up an environment is a b*tch. I think I switched over to mac mostly because of these little quirks when using windows shell.

The worst part is that I've had it set up for months. It's been running fine. Then I'm programming one day and my commands aren't recognized. I search the Internet for anything that will help. Everyone says the same thing. Then you come along and BAM! It works. I understand why you would switch to OSX. I've never had these kind of quirks with OSX before. But I'm too committed to Windows.

This work for me in Windows Server 2008, thank you so much!

windows - gulp command not found - error after installing gulp - Stack...

windows node.js gulp
Rectangle 27 8

I had a similar problem setting it up in windows 10. My answer is windows specific (look at the answers for modifying path in bash for a linux or OSX solution)

The core problem I had was that npm's folder was not registered in the path. I originally tried changing this in cmd prompt.

setx path "%path%;%appdata$\npm"

Note that I used setx instead of set to ensure that the update to the environmental variable remains. Also note that it's a backslash.

This should work but for me it didn't because setx has a limit of only accepting 1024 characters... (yes it's nonsensical to me as well).

So try the above and if you get a warning like did about reaching the 1024 limit, then you can do the other way I ended up doing.

First while youre still in the console, type: echo %appdata%\npm ... this is your npm folder that you want to add to the path so add it to your clipboard.

You have to go into the registry and reach the following folder:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

Then append the 'Path' value with the npm folder path in your clipboard. Reboot to activate the new value and you should now be good to go.

>npm install -g gulp
>gulp

Yes!!! Finally! I have looked all over for something to help. Almost all of the answers say to install it globally and it should work. I've installed, uninstalled, reinstalled, cleared cache, etc. At last, this worked. Thank you!

@Josh, glad I could get you running. Setting up an environment is a b*tch. I think I switched over to mac mostly because of these little quirks when using windows shell.

The worst part is that I've had it set up for months. It's been running fine. Then I'm programming one day and my commands aren't recognized. I search the Internet for anything that will help. Everyone says the same thing. Then you come along and BAM! It works. I understand why you would switch to OSX. I've never had these kind of quirks with OSX before. But I'm too committed to Windows.

This work for me in Windows Server 2008, thank you so much!

windows - gulp command not found - error after installing gulp - Stack...

windows node.js gulp
Rectangle 27 9

I itemize below the method that has served my needs on both my personal Windows and Ubuntu work PC. DO note that my method doesn't fiddle with PATH settings but involves a command you could save somewhere & copy and paste as needed:

  • Download the casperjs and phantomjs versions you want to use
  • Extract the downloaded phantomjs & copy its executable into the directory of step b
  • Copy the renamed casperjs folder to the directory of step b
  • Create and save a file config.json to the directory of step b
  • Whenever you want to work with a file, follow the Step 1 details above
  • The next step assumes that you are in the directory created in step b of Step 1 also have a file named first.js

Experimental config.js and first.js are listed below:

var casper = require('casper').create({
    pageSettings: {
        loadImages: false,
        loadPlugins: true,
        userAgent: 'Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'
    }
});
var url = "http://casperjs.org/";

casper.start(url).wait(60 * 1000 * 1, function() {
     casper.echo('1 min has passed');
     casper.capture('casperjs.png');
     casper.exit();
});

casper.run();

Addendum: download and save the details of screenshots.js and run it as

Run Tests: download & save the details of picturefill-test.js and run it as

phantomjs - Installing CasperJS on Windows: How to do it correctly? - ...

windows phantomjs casperjs
Rectangle 27 2

Use ';' as the separator. If your environment variables are set correctly, you should see your settings. If your PATH and CLASSPATH is correct, windows should recognize those commands. You do NOT need to restart your computer when installing Java.

That is on windows (semicolon) , on unix/linux it is ':' (colon)

java - How do I resolve ClassNotFoundException? - Stack Overflow

java class classpath classnotfoundexception
Rectangle 27 2

Use ';' as the separator. If your environment variables are set correctly, you should see your settings. If your PATH and CLASSPATH is correct, windows should recognize those commands. You do NOT need to restart your computer when installing Java.

That is on windows (semicolon) , on unix/linux it is ':' (colon)

java - How do I resolve ClassNotFoundException? - Stack Overflow

java class classpath classnotfoundexception
Rectangle 27 2

Use ';' as the separator. If your environment variables are set correctly, you should see your settings. If your PATH and CLASSPATH is correct, windows should recognize those commands. You do NOT need to restart your computer when installing Java.

That is on windows (semicolon) , on unix/linux it is ':' (colon)

java - How do I resolve ClassNotFoundException? - Stack Overflow

java class classpath classnotfoundexception