python: Change the scripts working directory to the script’s own directory

I run a python shell from crontab every minute: * * * * * /home/udi/foo/bar.py /home/udi/foo has some necessary subdirectories, like /home/udi/foo/log and /home/udi/foo/config, which /home/udi/foo/bar.py refers to. The problem is that crontab runs the script from a different working directory, so trying to open ./log/bar.log fails. Is there a nice way to tell the … Read more

Temporarily change current working directory in bash to run a command [duplicate]

This question already has answers here: How do I run a program with a different working directory from current, from Linux shell? (11 answers) Closed 7 years ago. I know I can use cd command to change my working directory in bash. But if I do this command: cd SOME_PATH && run_some_command Then the working … Read more

How to get current relative directory of your Makefile?

I have a several Makefiles in app specific directories like this: /project1/apps/app_typeA/Makefile /project1/apps/app_typeB/Makefile /project1/apps/app_typeC/Makefile Each Makefile includes a .inc file in this path one level up: /project1/apps/app_rules.inc Inside app_rules.inc I’m setting the destination of where I want the binaries to be placed when built. I want all binaries to be in their respective app_type path: … Read more

How do I get the directory that a program is running from?

Is there a platform-agnostic and filesystem-agnostic method to obtain the full path of the directory from where a program is running using C/C++? Not to be confused with the current working directory. (Please don’t suggest libraries unless they’re standard ones like clib or STL.) (If there’s no platform/filesystem-agnostic method, suggestions that work in Windows and … Read more

how to get the current working directory’s absolute path from irb

I’m running Ruby on Windows though I don’t know if that should make a difference. All I want to do is get the current working directory’s absolute path. Is this possible from irb? Apparently from a script it’s possible using File.expand_path(__FILE__) But from irb I tried the following and got a “Permission denied” error: File.new(Dir.new(“.”).path).expand … Read more

Determine project root from a running node.js application

Is there a different way, other than process.cwd(), to get the pathname of the current project’s root-directory. Does Node implement something like ruby’s property, Rails.root,. I’m looking for something that is constant, and reliable. 32 Answers 32 There are many ways to approach this, each with their own pros and cons: require.main.filename From http://nodejs.org/api/modules.html: When … Read more