Results 1 to 4 of 4
- 11-24-2008, 09:03 PM #1
[SOLVED] opening/running a program from java
Does Java have an API or command to say open up a text document in notepad without having to code a shell and frame and get the Notepad framework attached to it? Similar action would be just typing Eclipse from the command prompt to run the eclipse program(assuming I'm in the directory).
My program creates a build file(a text file at this point) with some information in it and instead of having to navigate to the directory and open it(I'm lazy), I want to attach a listener, that will open notepad and load said file, to a button. Is this possible and where do I look if it is.
- 11-24-2008, 10:44 PM #2
So I managed to get it to open notepad but I can't get it to load my text document into notepad.
is the basic code to get notepad open. I tried doingJava Code:Runtime load = Runtime.getRuntime(); try { load.exec("C:\\WINDOWS\\system32\\notepad.exe"); } catch (IOException e) { e.printStackTrace(); }because I can't figure out what String[] envp is supposed to be/do. Any explanation of what envp is supposed to be aside fromJava Code:load.exec("C:\\WINDOWS\\system32\\notepad.exe", envp/*replace with null*/, build.getBuildFile().getAbsolutePath());?array of strings, each element of which has environment variable settings in the format name=value, or null if the subprocess should inherit the environment of the current process.
By the way, the error I get when running (notepad, null, myFile) is Cannot run program "C:\WINDOWS\system32\notepad.exe" (in directory "C:\Documents and Settings\carsonrs\Desktop\TestFiles\Natoil-Dev.txt"): CreateProcess error=267, The directory name is invalid.
I'm thinking it's trying to run notepad using my text file instead of running my textfile using notepad, so I swapped the arguments and was given the option to swap the arguments back or change the constructor to exec(String)
I mean, honestly, is it too much to specify what program to use for what file and have it do it. Come on Java work with me.Last edited by xcallmejudasx; 11-24-2008 at 10:52 PM. Reason: Didn't ask a question
- 11-24-2008, 11:04 PM #3
Turns out the string array was the saving point once I tweaked things a bit.
New working code
Java Code:Runtime load = Runtime.getRuntime(); String[] cmd = {"notepad", build.getBuildFile().getAbsolutePath()}; try { load.exec(cmd); } catch (IOException e) { e.printStackTrace(); }
- 11-25-2008, 08:12 AM #4
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 8
Similar Threads
-
Opening for java Professionals
By careertechy in forum Jobs OfferedReplies: 2Last Post: 01-15-2009, 12:40 PM -
When to use –client and -server option while running a java program
By Java Tip in forum java.langReplies: 0Last Post: 04-04-2008, 02:49 PM -
Running java program with arguments in Unix"
By gvi in forum Advanced JavaReplies: 2Last Post: 11-08-2007, 07:01 PM -
Call a main method from within a running program
By zoe in forum New To JavaReplies: 1Last Post: 08-07-2007, 06:16 AM -
job opening for java architect
By athira in forum Jobs OfferedReplies: 0Last Post: 07-26-2007, 12:10 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks