Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8763711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:50:49+00:00 2026-06-13T15:50:49+00:00

I open office files (docx, xlsx) by using Runtime.getRuntime().exec(String cmd) function. Simultaneously I store

  • 0

I open office files (docx, xlsx) by using Runtime.getRuntime().exec(String cmd) function. Simultaneously I store meta data of these files in a database. In order to keep integrity I lock the file with a flag in the meta data so that no other user concurrently can modify the file. This implies that the flag must be automatically resetted after the user closes the file (e.g. closes the external process).

Here’s the snippet that opens the file:

File file = new File("c:/test.docx");
Process process = null;
if(file.getName().endsWith("docx")) {
    process = Runtime.getRuntime().exec("c:/msoffice/WINWORD.EXE "+file.getAbsolutePath());
} else if(file.getName().endsWith("xlsx")) {
    process = Runtime.getRuntime().exec("c:/msoffice/EXCEL.EXE "+file.getAbsolutePath());
}
if(process!=null) {
    new ProcessExitListener(file, process);
}

Here’s my listener that waits until the user closes the file (and finally unlocks the file by setting the flag in the meta data):

private class ProcessExitListener extends Thread {

    private File file;
    private Process process;

    public ProcessExitListener(File file, Process process) throws IOException {
        this.setName("File-Thread ["+process.toString()+"]");
        this.file = file;
        this.process = process;
        this.start();
    }

    @Override
    public void run() {
        try {
            process.waitFor();
            database.unlock(file);
        } catch (InterruptedException ex) {
            // print exception
        }
    }
}

This works fine for different file types, e.g. if I open 1 docx and 1 xlsx file simultaneously. But when opening 2 docx files, one of the process exits right after it has been initialized.

Any ideas why ?

Thanks for your help in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T15:50:50+00:00Added an answer on June 13, 2026 at 3:50 pm

    But when opening 2 docx files, one of the process exists right after it has been initialized.

    Probably because winword.exe process finds out that there is already one instance of it running, so instead of keeping two instances in memory, it just asks the first instance to open the second document. Don’t know how it looks from GUI perspective, but looking at the task manager, try opening two Word documents from Windows Explorer. The second file won’t cause second winword.exe process to start.

    I can reproduce the exact same behaviour on Ubuntu Linux. When I ran:

    $ geany foo.txt
    

    and the geany editor wasn’t yet running, the console hangs until I close the editor. But if instead I open another terminal and call:

    $ geany bar.txt
    

    this returns immediately and bar.txt is simply opened as another tab in already existing process.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm searching for strings inside a word document using the Open XML Office SDK
Today I needed to parse some data out from an xlsx file (Office open
I want to read MS word files which were created using older office tool
I'm using the COM objects from Office 2007 to handle and print ms-office files.
I'm using Interop to open and read Excel files. rangeBegin = templateWorksheet.get_Range(<special cell adressing
Using Interop to render a number of Excel files to XPS. Many .Open fail
I have relatively sensitive data in .docx, .xlsx and PDF files that all need
I'm working on an Open Office document with a partner and we are using
I am using the JODConverter library V 3.0 Beta 4 along with Open Office
Is there anyway to use the Open Office SDK 2.0 to save a PowerPoint

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.