Results 1 to 6 of 6
  1. #1
    t500yo is offline Member
    Join Date
    Jun 2010
    Posts
    14
    Rep Power
    0

    Default Java/Ubuntu: Runtime.getRuntime().exec(..) gives an error

    Hello everybody
    I have got this problem with a simple program I am writing at a ubuntu system, but I always get this message:

    --engine: -c: regel 0: onverwacht bestandseinde tijdens zoeken naar bijpassende '"'
    --engine: -c: line 0: unexpected end of file while looking for matching '"'

    The command (see below) works in the gnome terminal, so why does it not work using Java??

    Thank you in advance!
    Jos
    ------

    Java Code:
    String command = "/bin/bash -c \"centroid_fold --engine 'CONTRAfold' --gamma 1024 '/home/jos/Bureaublad/library.fasta'\"";
    
    try {
    	Process r = Runtime.getRuntime().exec(command);
    	BufferedReader in = new BufferedReader(new InputStreamReader(r.getInputStream()));
    	String line = null;
    	while ((line = in.readLine()) != null) {
    		System.out.println(line);
    	}
    	if(r.waitFor()!=0) {
    		System.out.println(new BufferedReader(new InputStreamReader(r.getErrorStream())).readLine());
    	}
    } catch(Exception e) {
    	System.out.println("Error: "+e.getMessage());
    }

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,436
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by t500yo View Post
    Hello everybody
    I have got this problem with a simple program I am writing at a ubuntu system, but I always get this message:

    --engine: -c: regel 0: onverwacht bestandseinde tijdens zoeken naar bijpassende '"'
    --engine: -c: line 0: unexpected end of file while looking for matching '"'

    The command (see below) works in the gnome terminal, so why does it not work using Java??

    Thank you in advance!
    Jos
    ------

    Java Code:
    String command = "/bin/bash -c \"centroid_fold --engine 'CONTRAfold' --gamma 1024 '/home/jos/Bureaublad/library.fasta'\"";
    
    try {
    	Process r = Runtime.getRuntime().exec(command);
    	BufferedReader in = new BufferedReader(new InputStreamReader(r.getInputStream()));
    	String line = null;
    	while ((line = in.readLine()) != null) {
    		System.out.println(line);
    	}
    	if(r.waitFor()!=0) {
    		System.out.println(new BufferedReader(new InputStreamReader(r.getErrorStream())).readLine());
    	}
    } catch(Exception e) {
    	System.out.println("Error: "+e.getMessage());
    }
    Use one of the other exec( ... ) methods where you pass the name of the process and the arguments as separate Strings. Java splits your single String different from how your bash shell would split them.


    kind regards,

    Jos (yep, also Jos ;-)

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by JosAH View Post
    Jos (yep, also Jos ;-)
    Lord help us all if this is another Grolsch drinking orange flag waving flying Dutchman!

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,436
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Fubarable View Post
    Lord help us all if this is another Grolsch drinking orange flag waving flying Dutchman!
    Mwah, there are also normal people named 'Jos'; I'm the exception to the rule because I fell on my head when I was a baby.

    kind regards,

    Jos (<-- the one and only! ;-)

  5. #5
    t500yo is offline Member
    Join Date
    Jun 2010
    Posts
    14
    Rep Power
    0

    Default Thnx!

    Thanks mates!
    Especially you Jos ;-) It took me another day to create something that actually works on both ubuntu and windows (I'm not an expert on both OS's) but It looks like I can finish this assignment. (unfortunately now I need to do some things with tables, and that might be hard ;-) - but I know where to find you ^-^)

    Off topic;
    Ow, Grolsch really has done it, right? Stupid beer makers - although even I have to admit that it is clever; they have all the attention they wanted ;-)
    I'm not a real supporter of the Dutch soccer team - although I'm starting to be one since they are in the finals.. (And I still don't think they have a chance to win the finals - we are not that great, we just have luck)

    ORANGE ORANGE
    Ow - really - I'm nuts too!

  6. #6
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,436
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by t500yo View Post
    Off topic;
    Ow, Grolsch really has done it, right? Stupid beer makers - although even I have to admit that it is clever; they have all the attention they wanted ;-)
    I'm not a real supporter of the Dutch soccer team - although I'm starting to be one since they are in the finals.. (And I still don't think they have a chance to win the finals - we are not that great, we just have luck)

    ORANGE ORANGE
    Ow - really - I'm nuts too!
    I thought it was Bavaria that had sent the 'babes' over to the WC. Us Grolsch drinkers are way too sensible to do that (ahem) and above all, Bavaria beer stinks. ;-)

    kind regards,

    Jos

Similar Threads

  1. Slow Output reading with Runtime.getRuntime().exec()
    By gmcouto in forum Advanced Java
    Replies: 8
    Last Post: 05-14-2010, 10:42 AM
  2. problem with Runtime.getRuntime().exec when running java in .bat
    By Shayko in forum Threads and Synchronization
    Replies: 2
    Last Post: 01-27-2010, 07:46 PM
  3. help with Runtime.getRuntime().exec
    By collin389 in forum AWT / Swing
    Replies: 3
    Last Post: 11-09-2009, 04:22 AM
  4. Problem with Runtime.getRuntime().exec with Linux Commands
    By swapnilnawale in forum Threads and Synchronization
    Replies: 1
    Last Post: 09-23-2009, 10:23 PM
  5. grep on multiple files using Runtime.getRuntime().exec()
    By cprash.aggarwal in forum Advanced Java
    Replies: 3
    Last Post: 02-11-2009, 06:55 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
  •