该进程无法访问该文件,因为该文件正在被另一个进程使用
我有一个用 C 语言编写的程序,它将在运行 2 小时后重新启动我的 Java 应用程序。
首先,我使用批处理文件运行我的java程序,
@echo off
java -server -Xmx1024m -Xbootclasspath/p:"bin;" website.Server >>C:\web_logs\console.log
它工作得很好,但2小时后我使用 Runtime.getRuntime();在 Java 中进行干净准备的重启;执行我的 C 程序“Restarter.exe”。 Restart.exe 杀死了 java 进程,也杀死了 cmd 进程(我杀死了命令进程,因为我不确定为什么它一直说“...进程无法访问该文件...被另一个进程使用。”
并且它有效如果我在参数之后不使用 Windows 日志记录“>>”就很好了,
只是当我尝试记录控制台时,它不会重新启动。 windows 命令提示符只能记住这么多,所以我使用“>>”来记录文件并稍后读取它,因为这是我不需要做的事情。我使用的是 Windows 计算机,
所以我的问题是,在我的参数之后如何仍然使用“>>”来记录控制台,以便它仍然重新启动?杀死 java 和 cmd 吗?我可以做些什么来解决这个问题或结束该进程,以便我可以解析相同的文件
?
I have a program I made in C that will restart my Java application after running for 2 hours.
First of all, I run my java program using a batch file,
@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."
And it works just fine if I don't use the windows logging ">>" after my arguments.
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.
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?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议安装 Process Explorer,当您收到该错误消息时,使用“查找句柄”功能并查看哪个进程持有该文件的句柄。
回帖!
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.
Post back!
使用 TASKKILL /IM java.exe /f 然后重新启动您的 sonarqube 服务器。
Use TASKKILL /IM java.exe /f then restart your sonarqube server.