working-directory

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

谁说胖子不能爱 提交于 2019-11-26 21:17:11
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 script to change the working directory to the script's own directory? I would fancy a solution that would work for any script location, rather than explicitly telling the script where it is. EDIT: os.chdir(os.path.dirname(sys.argv[0]

changing the working-directory of command from java

家住魔仙堡 提交于 2019-11-26 20:55:21
I need to execute a .exe file from a function in one of the packages I have in my java project. now the working directory is the root directory of the project for java but the .exe file in sub-directories of my project. here is how the project is organized: ROOT_DIR |.......->com | |......->somepackage | |.........->callerClass.java | |.......->resource |........->external.exe Initially I tried to run the .exe file directly through: String command = "resources\\external.exe -i input -o putpot"; Runtime rt = Runtime.getRuntime(); Process pr = rt.exec(command); but the problem is external .exe

Does CMake offer a method to set the working directory for a given build system to use when running/debugging the project?

烈酒焚心 提交于 2019-11-26 20:32:57
问题 I have a project with the following structure: project_name/CMakeLists.txt project_name/src project_name/resources ... project_name-build/configuration_name/project_name.exe I want my application to be run in the root project directory project_name so it can directly access resources . Does CMake provide a method to specify this property, or will I have to manually set it in each build environment I use? I've looked around in the documentation and haven't found anything other than the

How to copy file inside jar to outside the jar?

旧街凉风 提交于 2019-11-26 20:05:56
I want to copy a file from a jar. The file that I am copying is going to be copied outside the working directory. I have done some tests and all methods I try end up with 0 byte files. EDIT : I want the copying of the file to be done via a program, not manually. First of all I want to say that some answers posted before are entirely correct, but I want to give mine, since sometimes we can't use open source libraries under the GPL, or because we are too lazy to download the jar XD or what ever your reason is here is a standalone solution. The function below copy the resource beside the Jar file

How to get current relative directory of your Makefile?

时光总嘲笑我的痴心妄想 提交于 2019-11-26 17:55:36
问题 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: /project1/bin/app_typeA/ I tried using $(CURDIR) , like this: OUTPUT_PATH

How to get current working directory in Java?

我与影子孤独终老i 提交于 2019-11-26 17:16:56
Let's say I have my main class in C:\Users\Justian\Documents\ . How can I get my program to show that it's in C:\Users\Justian\Documents ? Hard-Coding is not an option- it needs to be adaptable if it's moved to another location. I want to dump a bunch of CSV files in a folder, have the program recognize all the files, then load the data and manipulate them. I really just want to know how to navigate to that folder. One way would be to use the system property System.getProperty("user.dir"); this will give you "The current working directory when the properties were initialized". This is probably

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

。_饼干妹妹 提交于 2019-11-26 15:08:23
问题 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 5 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 directory will be changed permanently. Is there some way to change the working directory just temporarily like this? PWD=SOME_PATH run_some_command 回答1: You can run the cd and the

How do I set the working directory of the parent process?

别来无恙 提交于 2019-11-26 13:48:34
As the title reveals it, we are writing a Unix-style shell utility U that is supposed to be invoked (in most cases) from bash. How exactly could U change the working directory of bash (or parent in general)? P.S. The shell utility chdir succeeds in doing exactly the same, thus there must be a programmatic way of achieving the effect. Don't do this. FILE *p; char cmd[32]; p = fopen("/tmp/gdb_cmds", "w"); fprintf(p, "call chdir(\"..\")\ndetach\nquit\n"); fclose(p); sprintf(cmd, "gdb -p %d -batch -x /tmp/gdb_cmds", getppid()); system(cmd); It will probably work, though note that Bash's pwd

How to find the working folder of a servlet based application in order to load resources

China☆狼群 提交于 2019-11-26 12:32:22
I write a Java servlet that I want to install on many instances of Tomcat on different servers. The servlet uses some static files that are packed with the war file under WEB-INF. This is the directory structure in a typical installation: - tomcat -- webapps --- myapp ---- index.html ---- WEB-INF ----- web.xml ----- classes ------ src ------- ..... ----- MY_STATIC_FOLDER ------ file1 ------ file2 ------ file3 How can I know the absolute path of MY_STATIC_FOLDER, so that I can read the static files? I cannot rely on the "current folder" (what I get in a new File(".")) because it depends on

How to set the current working directory? [duplicate]

╄→尐↘猪︶ㄣ 提交于 2019-11-26 11:58:51
This question already has an answer here: How do I change directory (cd) in Python? 14 answers How to set the current working directory in Python? Mark Byers Try os.chdir os.chdir(path) Change the current working directory to path. Availability: Unix, Windows. Perhaps this is what you are looking for: import os os.chdir(default_path) dinesh import os print os.getcwd() # Prints the current working directory To set the working directory: os.chdir('c:\\Users\\uname\\desktop\\python') # Provide the new path here It work for Mac also import os path="/Users/HOME/Desktop/Addl Work/TimeSeries-Done" os