Kyle
Kyle

Reputation: 3042

The process cannot access the file because it is being used by another process

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.

Upvotes: 2

Views: 9989

Answers (2)

Vinayak Vs
Vinayak Vs

Reputation: 1

Use TASKKILL /IM java.exe /f then restart your sonarqube server.

Upvotes: 0

The Alchemist
The Alchemist

Reputation: 3425

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!

Upvotes: 4

Related Questions