Results 1 to 4 of 4
  1. #1
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    6

    Default [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.

  2. #2
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    6

    Default

    So I managed to get it to open notepad but I can't get it to load my text document into notepad.

    Java Code:
    Runtime load = Runtime.getRuntime();
    try {
    	load.exec("C:\\WINDOWS\\system32\\notepad.exe");
    } catch (IOException e) {
    	e.printStackTrace();
    }
    is the basic code to get notepad open. I tried doing
    Java Code:
    load.exec("C:\\WINDOWS\\system32\\notepad.exe", envp/*replace with null*/, build.getBuildFile().getAbsolutePath());
    because I can't figure out what String[] envp is supposed to be/do. Any explanation of what envp is supposed to be aside from
    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

  3. #3
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    6

    Default

    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();
    					}

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    For Java 6, read the API docs for DeskTop (and it's open method).

Similar Threads

  1. Opening for java Professionals
    By careertechy in forum Jobs Offered
    Replies: 2
    Last Post: 01-15-2009, 12:40 PM
  2. Replies: 0
    Last Post: 04-04-2008, 02:49 PM
  3. Running java program with arguments in Unix"
    By gvi in forum Advanced Java
    Replies: 2
    Last Post: 11-08-2007, 07:01 PM
  4. Replies: 1
    Last Post: 08-07-2007, 06:16 AM
  5. job opening for java architect
    By athira in forum Jobs Offered
    Replies: 0
    Last Post: 07-26-2007, 12:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •