DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2004
    Posts
    3

    Running word using a java programm in a Mac environment

    Ok,

    This is the problem

    I am trying to open a word document using runtime.exec.
    I have some working code in Windows, which starts the desired document in dos mode. I rely on the system to recognise the type of the file, so it starts the right program for the job.

    My question is how do I do this in MAC OSX. If I start the doc file in the shell it will also automatically call word to run the application. So I want to execute shell commands using runtime.exec
    Here is the code I use in windows, and the second part is something I tried on the mac. Can anyone see what I do wrong or what I need to do to get the stuff working.

    public void openFile(String target) throws InterruptedException
    {
    File targetFile = new File(target);
    boolean running = true;
    String [] openWord = new String [3];
    openWord[0] = "cmd";
    openWord[1] = "/c";
    openWord[2] = targetFile.toString();

    try
    {
    Runtime runtime= Runtime.getRuntime();
    Process proc=null;
    proc=runtime.exec(openWord);
    System.out.println("Maximum memory usage " + runtime.maxMemory() + " Bytes");
    while (running)
    {
    if (proc.waitFor() != 0)
    {
    try
    {
    Thread.sleep(500);
    System.out.print(".");
    }
    catch (InterruptedException ie)
    {
    System.out.println("InterruptedException " + ie);
    }
    }
    else
    {
    System.out.println("Process " + targetFile.getAbsolutePath() + " has ended");
    running = false;
    }
    }
    }

    catch (IOException e)
    {
    System.out.println(e);
    }
    System.out.println(true);
    }



    Code I tried on the Mac

    public class RunWord
    {
    public static void main (String [] arg)
    {
    String openWord [] = {"open", users/company/documents/Bud.doc");
    String echo[] = {"echo", "Anyone out there?"};
    try
    {
    Process proc = Runtime.getRuntime().exec(openWord);
    Process proc2 = Runtime.getRuntime().exec(echo);
    }
    catch (IOException ioe)
    { System.out.println("IOException " + ioe);
    }
    }


    Thanks in advance

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    ironically..how they make their money..
    eschew obfuscation

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links