-
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
-
ironically..how they make their money..
eschew obfuscation
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
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
|
Bookmarks