windows 该进程无法访问该文件,因为它正被另一个进程使用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3598821/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The process cannot access the file because it is being used by another process
提问by Kyle
I have a program I made in C that will restart my Java application after running for 2 hours.
我有一个用 C 编写的程序,它会在运行 2 小时后重新启动我的 Java 应用程序。
First of all, I run my java program using a batch file,
首先,我使用批处理文件运行我的 java 程序,
@echo off
java -server -Xmx1024m -Xbootclasspath/p:"bin;" website.Server >>C:\web_logs\console.log
It works perfectly fine, but after the 2 hours is up I use Runtime.getRuntime(); in Java for a clean prepared restart; to execute my C program "Restarter.exe". Restart.exe kills the java process and also kills the cmd process (I killed the command process because I wasn't sure why it keeps saying "...process cannot access the file... used by another process."
它工作得很好,但在 2 小时后我使用 Runtime.getRuntime(); 在 Java 中进行干净的准备重启;执行我的 C 程序“Restarter.exe”。Restart.exe 杀死 java 进程并杀死 cmd 进程(我杀死了命令进程,因为我不确定为什么它一直说“...进程无法访问文件...被另一个进程使用。”
And it works just fine if I don't use the windows logging ">>" after my arguments.
如果我在我的论点后不使用 Windows 日志记录“>>”,它就可以正常工作。
It's just when I try to log the console, it doesn't restart. I have a lot of debug going on in the console and the windows command prompt can only remember so much. So I used ">>" to log to a file and read it later. I don't want to log a file via java because it's something I don't need to do if I'm using a windows computer.
只是当我尝试登录控制台时,它不会重新启动。我在控制台中进行了很多调试,Windows 命令提示符只能记住这么多。所以我使用“>>”登录到一个文件并稍后阅读。我不想通过 java 记录文件,因为如果我使用的是 Windows 计算机,我不需要这样做。
So my question is, how can I still log the console using ">>" after my arguments so it still restarts? It keeps saying the process is being used but I thought I killed it by killing java and cmd? What can I do to fix that or end the process so I can parse the same file?
所以我的问题是,如何在我的参数后仍然使用“>>”登录控制台,以便它仍然重新启动?它一直说正在使用该进程,但我以为我是通过杀死 java 和 cmd 来杀死它的?我能做些什么来解决这个问题或结束这个过程,以便我可以解析同一个文件?
Thanks.
谢谢。
回答by The Alchemist
I recommend installing Process Explorer, and when you get that error message, use the "Find Handle" feature and see what process is holding a handle to that file.
我建议安装Process Explorer,当您收到该错误消息时,请使用“查找句柄”功能并查看哪个进程持有该文件的句柄。
Post back!
回帖!