Results 1 to 5 of 5
  1. #1
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default Executing a file from a location containing spaces.

    OK my problem is I'm not sure how I'm supposed to navigate to a file location that contains space because this code stops reading the file location at the first space.

    Java Code:
    Runtime run = Runtime.getRuntime();
    try {
         Process pp=run.exec("C:\\Riot Games\\League of Legends");
         }catch (Exception e) {
               e.printStackTrace();
    	   System.out.println(e.getMessage());
         }
    I get this error
    Java Code:
    java.io.IOException: Cannot run program "C:\Riot": CreateProcess error=2, The system cannot find the file specified
    	at java.lang.ProcessBuilder.start(Unknown Source)
    	at LoLStarter$startButtonListener.startLoad(LoLStarter.java:151)
    	at LoLStarter$startButtonListener.actionPerformed(LoLStarter.java:140)
    I feel like this is really simple but I cannot think of what this would be.
    Last edited by Dark; 06-23-2012 at 09:53 AM.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,730
    Blog Entries
    7
    Rep Power
    21

    Default Re: Executing a file from a location containing spaces.

    Try one of the other exec( ... ) methods (one that doesn't break up your String).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default Re: Executing a file from a location containing spaces.

    I'm looking in the exec api and the only thing I think I can use is the getLocalizedInputStream(InputStream in). I don't know how I would stop my string from getting broken up using .exec();.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,730
    Blog Entries
    7
    Rep Power
    21

    Default Re: Executing a file from a location containing spaces.

    You didn't look good enough; the exec(String[] cmdarray) version does what you want (it doesn't break up a single String).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default Re: Executing a file from a location containing spaces.

    Oh I misunderstood what you meant then. In the actual code I am passing it a String Array but it wasn't working. I found an example on how to use the exec(String[] cmdarray) version and its now working perfectly.

    Thanks JosAH for tolerating my derp moment.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

Similar Threads

  1. Replies: 2
    Last Post: 05-26-2011, 06:38 AM
  2. Replies: 18
    Last Post: 01-19-2011, 08:29 PM
  3. need to copy file from one location to another location
    By naveen.dpt2007 in forum New To Java
    Replies: 4
    Last Post: 02-28-2010, 04:53 PM
  4. Replies: 2
    Last Post: 12-10-2009, 01:06 PM
  5. Reading file data that contains no spaces
    By jdepue in forum Advanced Java
    Replies: 1
    Last Post: 08-01-2007, 05:58 AM

Posting Permissions

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