cwd

Perl getcwd ending forward slashes

余生长醉 提交于 2020-01-04 15:16:29
问题 I am doing a Perl script to attach another variable to the end of the current working directory, but I am having problems with using the module. If I run getcwd from D:\ , the value returned is D:/ (with forward slash) If I run getcwd from D:\Temp\ , the value returned is D:/temp (without forward slash) This makes the situation quite tricky because if I simply do: use Cwd; $ProjectName = "Project"; # This is a variable supplied by the user $directory = getcwd().$ProjectName."\/"; print

Using Perl on Windows, how can I ensure I get the path in the correct case following a chdir?

笑着哭i 提交于 2019-12-07 07:20:53
问题 Consider the following code: print cwd . "\n"; $str= "../source"; # note the lower case 's' chdir($str); print cwd . "\n"; If my current directory is c:\parentdir\Source (note the capital 'S'), the output of this will be: c:/parentdir/Source c:/parentdir/source This causes problems in a subroutine of mine that cares about the correct case of folder names. $str is passed in to my subroutine, so I can't know ahead of time whether it has the correct case. How do I determine the case-correct name

Using Perl on Windows, how can I ensure I get the path in the correct case following a chdir?

℡╲_俬逩灬. 提交于 2019-12-05 12:03:56
Consider the following code: print cwd . "\n"; $str= "../source"; # note the lower case 's' chdir($str); print cwd . "\n"; If my current directory is c:\parentdir\Source (note the capital 'S'), the output of this will be: c:/parentdir/Source c:/parentdir/source This causes problems in a subroutine of mine that cares about the correct case of folder names. $str is passed in to my subroutine, so I can't know ahead of time whether it has the correct case. How do I determine the case-correct name of a path that matches $str ? More detail here: I realize that ../source is a pathological example,

Is there a hook in Bash to find out when the cwd changes?

谁都会走 提交于 2019-12-03 05:06:28
问题 I am usually using zsh, which provides the chpwd() hook. That is: If the cwd is changed by the cd builtin, zsh automatically calls the method chpwd() if it exists. This allows to set up variables and aliases which depend on the cwd. Now I want to port this bit of my .zshrc to bash, but found that chpwd() is not recognized by bash. Is a similar functionality already existing in bash? I'm aware that redefining cd works (see below), yet I'm aiming for a more elegant solution. function cd() {

Is there a hook in Bash to find out when the cwd changes?

南笙酒味 提交于 2019-12-02 18:20:28
I am usually using zsh, which provides the chpwd() hook. That is: If the cwd is changed by the cd builtin, zsh automatically calls the method chpwd() if it exists. This allows to set up variables and aliases which depend on the cwd. Now I want to port this bit of my .zshrc to bash, but found that chpwd() is not recognized by bash. Is a similar functionality already existing in bash? I'm aware that redefining cd works (see below), yet I'm aiming for a more elegant solution. function cd() { builtin cd $@ chpwd } You would have to use a DEBUG trap or PROMPT_COMMAND . Examples: trap chpwd DEBUG #

subprocess.Popen using relative paths

感情迁移 提交于 2019-12-01 15:09:33
问题 The docs for Popen mention that you can't specify your executable path relative to the 'change working directory' kwarg. If cwd is not None, the child’s current directory will be changed to cwd before it is executed. Note that this directory is not considered when searching the executable, so you can’t specify the program’s path relative to cwd . But python's behaviour on my system seems to directly contradict this claim: wim@SDFA100461C:/tmp$ mkdir a wim@SDFA100461C:/tmp$ cp /bin/ls /tmp/a

How do I write a decorator that restores the cwd?

心不动则不痛 提交于 2019-11-28 19:13:38
How do I write a decorator that restores the current working directory to what it was before the decorated function was called? In other words, if I use the decorator on a function that does an os.chdir() , the cwd will not be changed after the function is called. CharlesB The path.py module (which you really should use if dealing with paths in python scripts) has a context manager: subdir = d / 'subdir' #subdir is a path object, in the path.py module with subdir: # here current dir is subdir #not anymore (credits goes to this blog post from Roberto Alsina) The answer for a decorator has been

How do I write a decorator that restores the cwd?

久未见 提交于 2019-11-27 12:03:00
问题 How do I write a decorator that restores the current working directory to what it was before the decorated function was called? In other words, if I use the decorator on a function that does an os.chdir() , the cwd will not be changed after the function is called. 回答1: The path.py module (which you really should use if dealing with paths in python scripts) has a context manager: subdir = d / 'subdir' #subdir is a path object, in the path.py module with subdir: # here current dir is subdir