我已经为我的应用程序创建了一个 jar 文件,以便用户可以从 Windows 资源管理器中运行它。它在自己的工作目录中加载一个 JSON 文件以进行某些设置(使用路径“.\config.json”)。但是,当我从 Windows 资源管理器的 jar 文件中运行它时,它找不到配置文件,而从命令行运行相同的 jar 可以工作。我假设这是因为资源管理器将工作目录设置为 jar 文件夹以外的其他目录。它把它设置成什么?(我怎样才能找到 jar 自己的文件夹?)
我正在尝试让我的maven项目的新开发人员尽可能轻松地开始.我正在使用并推荐IntelliJ IDEA作为它们的IDE.我对将maven项目导入IDEA的结果非常满意.我现在唯一的复杂功能是从surefire插件导入工作目录.
在我的pom.xml中,我有以下内容:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7.2</version>
<configuration>
<workingDirectory>target/work</workingDirectory>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
当我从命令行(mvn test)运行测试时,这很好用.当我创建新的Idea项目时,JUnit测试需要aditional设置.工作目录被忽略,我必须手动设置它才能正确运行测试.
你知道如何让Idea正确导入JUnit的工作目录吗?
import junit intellij-idea working-directory maven-surefire-plugin
网上有许多关于如何从 Notepad Plus Plus (NPP) 运行文件的示例。但是它们都没有考虑到当前工作目录是 NPP 可执行文件的位置,而不是文件的位置这一事实。
通常他们会这样:
cmd /K "$(FULL_CURRENT_PATH)"
Run Code Online (Sandbox Code Playgroud)
考虑以下 Python 脚本:
with open('somefile.txt', 'a') as file:
file.write('Hello there.\n')
Run Code Online (Sandbox Code Playgroud)
该文件将在 NPP 文件夹中创建,这完全不是大多数人所期望的。大多数人希望它与 Python 文件位于同一位置。
你也可以做这样的事情,它按预期工作,但这仅限于 Python 文件:
<Command name="Run This Python File" Ctrl="no" Alt="no" Shift="yes" Key="116">cmd /K python "$(FULL_CURRENT_PATH)"</Command>
Run Code Online (Sandbox Code Playgroud)
我不想在 Python 脚本中添加额外的代码来更改当前工作目录,因为通常不需要这样做。
我一直在努力解决这个问题,并提出了以下建议。此行位于NPP 文件夹中的“ shortcuts.xml ”中。
<Command name="Run This File" Ctrl="yes" Alt="no" Shift="no" Key="116">cmd /K "cd "$(CURRENT_DIRECTORY)" && "$(FULL_CURRENT_PATH)""</Command>
Run Code Online (Sandbox Code Playgroud)
所以你关闭 NPP,通过添加这一行来编辑“ shortcuts.xml ”,使用另一个编辑器,然后启动 NPP。要运行该文件,请使用Ctrl+F5组合键。
这在 Windows 10 中有效,但在 Windows XP 中失败。
如何调整它以在 Windows XP 中工作?
shell windows-xp notepad++ working-directory launching-application
我升级到RStudio 1.0.44,似乎knitr :: opts_knit $ set(root.dir = path)其中path是我的目录不像以前那样工作.它抛出一条消息:
The working directory was changed to /... inside a notebook chunk. The working
directory will be reset when the chunk is finished running. Use the knitr
root.dir option in the setup chunk to change the the working directory for
notebook chunks.
Run Code Online (Sandbox Code Playgroud)
此消息现在将出现在以下每个命令中.请注意,我还没有编织rmd.我只是在运行命令.通过setwd()直接在命令行中设置工作目录会返回getwd()中的正确路径,但是再次加载具有相对路径(./ ...)的文件将返回上面的消息.RStudio 0.99.896完全相同的rmd工作正常.我错过了什么?
sessionInfo()
R version 3.3.0 (2016-05-03)
Platform: x86_64-w64-mingw32/x64 (64-bit)
>Running under: Windows 7 x64 (build 7601) Service Pack 1
other attached packages:
[1] scales_0.4.0 ggplot2_2.1.0 xtable_1.8-2 data.table_1.9.6
[5] dplyr_0.4.3 …Run Code Online (Sandbox Code Playgroud) 我需要一种方法来杀死当前目录中正在运行的所有内容。我对 shell 有点陌生,所以请原谅我的愚蠢或可能不理解你的答案。我的理解还算不错,但如果您愿意花额外的时间来解释一下您对我的问题的解决方案到底是做什么的,我将不胜感激。
我在 Windows 中工作,想知道是否有办法从路径中删除当前工作目录?我知道这是 PowerShell 中的默认行为,但我需要它批量工作或在 Windows 命令行中工作。
在 UNIX 中,我只需确保我的$PATH变量不包含.. 有什么办法可以批量完成这个任务吗?这是当前的行为:
H:\tmp>dir
Volume in drive H has no label.
Volume Serial Number is E29C-7B61
Directory of H:\tmp
04/27/2018 10:39 AM <DIR> .
04/27/2018 10:39 AM <DIR> ..
04/27/2018 10:40 AM 37 dwk.bat
1 File(s) 37 bytes
2 Dir(s) 987,995,770,880 bytes free
H:\tmp>dwk.bat
dwk.bat has been run.
H:\tmp>
Run Code Online (Sandbox Code Playgroud)
这是期望的行为:
H:\tmp>dwk.bat
'dwk.bat' is not recognized as an internal or external command,
operable program or batch file.
H:\tmp>.\dwk.bat
dwk.bat …Run Code Online (Sandbox Code Playgroud) 所以我一直在尝试打开这样的非常基本的文件:inputFile = open("keywords.txt", "r")
但我收到这个错误:
FileNotFoundError: [Errno 2] No such file or directory: 'keywords.txt'
Run Code Online (Sandbox Code Playgroud)
这肯定是因为 Python 的默认工作目录不是我的 .py 文件所在的目录(如果我错了,请纠正我)。如何找到我正在工作的目录的确切路径,然后将Python的默认工作目录更改为它?
注意:我在OSX Mojave上使用VSCode和Anaconda (Python 3.6)
当我从任何文件夹(例如)启动 PowerShell 脚本时C:\Scripts,
脚本中的“当前”PowerShell 文件夹始终是用户配置文件文件夹
(例如c:\users\Joe;仅使用脚本进行测试Get-Location)
但应该是启动脚本的文件夹......
我怎样才能解决这个问题?
我正在尝试使用快捷方式以管理员身份运行 PowerShell 脚本。我尝试了很多方法,但还是不行:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -NoExit -Verb RunAs Start-Process powershell.exe -ArgumentList '-file C:\project\test.ps1'
Run Code Online (Sandbox Code Playgroud)
使用此命令,它将创建两个 PowerShell 窗口,并关闭一个窗口。
我也尝试过这个:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -NoExit Start-Process powershell.exe -Verb RunAs -File 'C:\project\test.ps1'
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?
如何在设计时从我的WPF应用程序获取应用程序的目录?我需要在设计时访问应用程序当前目录中的资源,而我的XAML正在设计器中显示.我无法在设计时使用此问题中指定的解决方案,System.IO.Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName)并System.Reflection.Assembly.GetExecutingAssembly().Location指向IDE的位置(Visual Studio ... Common7或其他东西).
根据要求进一步明确我的目标:我想在设计时访问数据库表并显示该数据的图形.设计是在Visual Studio 2008中完成的,所以我需要的是针对特定问题的非常具体的解决方案,即获取我的应用程序的程序集目录.