Invoke RealVNC using java code(java.lang.Runtime)

I would like to invoke vncviewer exe whenever user presses a button.Please help

What part are you having trouble with? What have you done so far?
Note that you have two main problems to solve here.
Do you know how to perform a given action when a button is pressed? If not, google for a swing tutorial. You'll want some kind of Listener, though I don't know the specific class name.
Do you know how to invoke another executable program from within a Java app? If not, look into Runtime.exec.

Similar Messages

  • Invoke exe through java code(using java.lang.Runtime)

    Iam trying to invoke an exe from java code.If i give the complete path for that exe it is running fine .But if i set the environment variable and directly execute the exe through command prompt it iss running fine , but it fails to run when i do the same using java code i.e. java.lang.Runtime.exec function

    Give "//" for directory seperator.
    E.g. r.exec("c://test//test.exe",null);
    Why? That doesn't look correct.It is correct. It will work fine. Try it out.But it doesn't add or solve anything. A forward slash
    does not need to be escaped.'
    It's not even escaping. It's just doubling up. If that works, I'd bet "C://///test///////test.exe" does also.

  • Java.lang.Runtime.exec problem in ubuntu 9.10

    Hi:
    I tried to run some command in the java code , for example "grass64 -text /home/data/location", this command works well in the terminal, however when I call it in the java code I got some excepetions.
    My code is :
    public class Grass {
         public static String grassBatJob="GRASS_BATCH_JOB";
         public void run(String cmd,String jobPath) {
              //set the environments variables
              Map<String, String> env=new HashMap<String, String>();
              env.put(grassBatJob, jobPath);
              String gisDataBase="/home/kk/grass/GrassDataBase";
              String location="spearfish60";
              String mapset="PERMANENT";
              cmd=cmd+" "+gisDataBase+"/"+location+"/"+mapset;
              CommandLine line=new CommandLine(cmd);
              //the real cmd should be >>grass64 -text /home/kk/grass/GrassDataBase/spearfish60/PERMANENT
              System.out.println("start line=="+line.toString());
              DefaultExecutor de=new DefaultExecutor();
              try {
                   int index=de.execute(line,env);
                   System.out.println(index);
              } catch (ExecuteException e) {
                   e.printStackTrace();
              } catch (IOException e) {
                   e.printStackTrace();
         public static void main(String[] args) {
              String jobPath=Grass.class.getResource("grass.sh").getFile();
              new Grass().run("grass64 -text", jobPath);
    The real cmd I want to execute is "grass64 -text /home/kk/grass/GrassDataBase/spearfish60/PERMANENT" with the envrionment variable "GRASS_BATCH_JOB=jobPath",it works well in the ternimal ,however in my application I got the exception"
    java.io.IOException: Cannot run program "grass64 -text /home/kk/grass/GrassDataBase/spearfish60/PERMANENT": java.io.IOException: error=2, No such file or directory
         at java.lang.ProcessBuilder.start(ProcessBuilder.java:459)
         at java.lang.Runtime.exec(Runtime.java:593)
         at org.apache.commons.exec.launcher.Java13CommandLauncher.exec(Java13CommandLauncher.java:58)
         at org.apache.commons.exec.DefaultExecutor.launch(DefaultExecutor.java:246)
         at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:302)
         at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:149)
         at org.kingxip.Grass.run(Grass.java:27)
         at org.kingxip.Grass.main(Grass.java:38)
    Caused by: java.io.IOException: java.io.IOException: error=2, No such file or directory
         at java.lang.UNIXProcess.<init>(UNIXProcess.java:148)
         at java.lang.ProcessImpl.start(ProcessImpl.java:65)
         at java.lang.ProcessBuilder.start(ProcessBuilder.java:452)
         ... 7 more
    I wonder why?

    Thanks for all of your reply, and now I can run the command, however I met some problems when I tried to get the result of the exec.
    The core codes are shown below:
    String cmd="g.version";
    String[] exe={"bash","-c",cmd};
    Process p1=Runtime.getRuntime.exec(exe,env); // the env has been set
    GrassThread outThread=new GrassThread("out", p1.getInputStream());
    outThread.start();
    GrassThread errorThread=new GrassThread("error", p1.getErrorStream());
    errorThread.start();
    int exitVal = p1.waitFor();
    String resu=outThread.sb.toString();
    System.out.println("==========the output start========");
    System.out.println(resu);
    System.out.println("==========the output end========");
    System.out.println("ExitValue: " + exitVal); //------------------> line one
    public class GrassThread extends Thread{
         public StringBuffer sb=new StringBuffer();
         public GrassThread(String type,InputStream is) {
              this.type=type;
              this.is=is;
         public void run() {
              try {
                   InputStreamReader isr = new InputStreamReader(is);
                   BufferedReader br = new BufferedReader(isr);
                   String line = null;
                   while ((line = br.readLine()) != null) {
                        System.out.println(type + ">" + line);
                        sb.append(line).append("\r");  // ----------------------------> line two
    }I define a StringBuffer in the GrassThread to save the output (see the code where I marked by "line two"), and when the process complete, I check the StringBuffer to get the output (see code where I marked by "line one"), however the output in the console of the IDE are :
    ----------- output in the console of the IDE start -------------
    ==========the output start========
    ==========the output end========
    ExitValue: 0
    out>GRASS 6.4.0RC5 (2009)
    ----------output in the console of the IDE end--------------------
    I can not understand, in the code "line one", I first get the output using "System.out.println(resu);",then I print the exitvalue,but why the order of the output in the console is not what I expected?
    Another question, the code above assume the output can be got from the Process's getInputStream, however sometimes the output maybe come from the Process's getErrorStream, so how to handle it?
    Edited by: apachemaven on 2010-3-5 ??5:38

  • While trying to invoke the method java.lang.String.length() of an object loaded from local variable 'payload'

    Hi,
    Our PI is getting data from WebSphere MQ and pushing to SAP. So our sender CC is JMS and receiver is Proxy. Our PI version is 7.31.
    Our connectivity between the MQ is success but getting the following error while trying to read the payload.
    Text: TxManagerFilter received an error:
    [EXCEPTION]
    java.lang.NullPointerException: while trying to invoke the method java.lang.String.length() of an object loaded from local variable 'payload'
           at com.sap.aii.adapter.jms.core.channel.filter.ConvertJmsMessageToBinaryFilter.filter(ConvertJmsMessageToBinaryFilter.java:73)
           at com.sap.aii.adapter.jms.core.channel.filter.MessageFilterContextImpl.callNext(MessageFilterContextImpl.java:204)
           at com.sap.aii.adapter.jms.core.channel.filter.InboundDuplicateCheckFilter.filter(InboundDuplicateCheckFilter.java:348)
           at com.sap.aii.adapter.jms.core.channel.filter.MessageFilterContextImpl.callNext(MessageFilterContextImpl.java:204)
    I have searched SDN but couldn't fix it. Please provide your suggestion.
    With Regards
    Amarnath M

    Hi Amarnath,
    Where exactly you are getting this error?
    If you are getting at JMS Sender communication channel, try to stop and start the JMS communication channel and see the status, also use XPI Inspector to get the exact error log.
    for reference follow below blogs:
    Michal's PI tips: ActiveMQ - JMS - topics with SAP PI 7.3
    Michal's PI tips: XPI inspector - help OSS and yourself
    XPI Inspector

  • Approval task SP09: Evaluation of approvalid failed with Exception: while trying to invoke the method java.lang.String.length() of an object loaded from local variable 'aValue'

    Hi everyone,
    I just installed SP09 and i was testing the solution. And I found a problem with the approvals tasks.
    I configured a simple ROLE approval task for validate add event. And when the runtime executes the task, the dispatcher log shows a error:
    ERROR: Evaluation of approvalid failed with Exception: while trying to invoke the method java.lang.String.length() of an object loaded from local variable 'aValue'
    And the notifications configured on approval task does not start either.
    The approval goes to the ToDO tab of the approver, but when approved, also the ROLE stays in "Pending" State.
    I downgraded the Runtime components to SP08 to test, and the approvals tasks works correctly.
    Has anyone passed trough this situation in SP09?
    I think there is an issue with the runtime components delivered with this initial package of SP09.
    Suggestions?

    Hi Kelvin,2016081
    The issue is caused by a program error in the Dispatcher component. A fix will be provided in Identity Management SP9 Patch 2 for the Runtime component. I expect the patch will be delivered within a week or two.
    For more info about the issue and the patch please refer to SAPNote 2016081.
    @Michael Penn - I might be able to assist if you provide the ticket number
    Cheers,
    Kristiyan
    IdM Development

  • Hi java.lang.System.gc() vs java.lang.Runtime.gc()

    hi all what is the exact diff.,
    java.lang.System.gc() vs java.lang.Runtime.gc()
    why dont I call Runtime.gc() like System.gc(), is ther any possibility ?
    Thanks in advance

    Thanks, but I just want to call Runtime.gc() like
    System.gc() forcefully to invoke finalize() method
    Thanks in advanceThe calls are the same. Read the javadoc:
    http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html#gc()
    public static void gc()
    Runs the garbage collector.
    Calling the gc method suggests that the Java Virtual Machine expend effort toward recycling unused objects in order to make the memory they currently occupy available for quick reuse. When control returns from the method call, the Java Virtual Machine has made a best effort to reclaim space from all discarded objects.
    The call System.gc() is effectively equivalent to the call:
    Runtime.getRuntime().gc()

  • How to use java.lang.Class.getMethod() and java.lang.reflect.Method.invoke(

    I want to call a specified method of one class dynamically. I use the method
    "getMethod()" in package "java.lang.Class" to get method and "invoke()" in
    " java.lang.reflect.Method " to invoke method.
    The problem is as following :
    1. There are two argument in this method "getMethod(String MethodName , Class[] paremterTypes)" in package "Class". I have no idea about the second parameter " Class[] parameterTypes ".what does the argument exactly mean ?
    2. There are two argument in the method "invoke(object obj, object[] obj)" in package "Method".
    I have no idea about the second parameter "object[] obj ".what is mean ?
    I pass " null " value to it and it works.But i pass anothers ,jvm will throw exception.

    I have a generic Method Executer that has a method like
    public Object execute(String className, String methodName, Object args)
        String fullClassName = packageName + className ;
        Class delegateClass = Class.forName(fullClassName);
        BaseDelegate delegate = (BaseDelegate)delegateClass.newInstance();
        Method method = null;
        if (args == null)
            method = delegateClass.getMethod(methodName, new Class[] {});
            obj = method.invoke(delegate,new Object[] {});
        else
            method = delegateClass.getMethod(methodName, new Class[] {args.getClass()});
            obj = method.invoke(delegate, new Object[]{args});
       }This seems to have problems when I call the method from a class like:
    execute("CategoryDelegate", "getCategoryById", new Integer(4144));(I get a NoSuchMethodException)
    The method I am trying to execute in CategoryDelegate looks like:
    public Category getCategoryById(int categoryId) throws DelegateExceptionI think it has to deal with the difference in the way we handle Primitive Wrappers and Objects. Wrapper we have to use Interger.TYPE and with the rest of the Objects we have to use obj.class.
    Am I doing something wrong here? Any suggestions to make it work for primitive wrappers as well as Objects?

  • Using java.lang.reflect.Method.invoke on a static method?

    This is probably a FAQ, but I am finding it impossible to construct a search which answers this question for me.
    How do I call java.lang.reflect.Method.invoke on a static (e.g. class) method? Is it even possible?
    Thanks,
    dwh

    Is this of any help?
    http://www.esus.com/javaindex/j2se/jdk1.2/javalang/reflection/reflection.html
    Cheers,
    Joris

  • How to use Java.lang.Math to calculate; Advice programming

    Hi, all!
    I am trying to teach myself Java, and am using the MindQ CDs to do it. I'm dreadfully stuck on this one exercise, and I could use some help figuring out how to properly call a Math method, store the variables, and print the results. I've programmed other methods successfully before; for some reason I just can't figure this one out. I've tried about fifty different configurations; maybe I can get some good advice here? Thanks!
    import java.io.*;
    import java.util.Random;
    import java.lang.Math;
    public class JavaCalcs {
        public static void main(String args[]) {
            System.out.println("Starting JavaComputations...");
            //main method variable declarations
            int z, y, x, w;
            int A = -12;
            int B = 2;
            z = A & B;
            y = A | B;
            x = A >> B;
            w = A >>> B;
            System.out.println(z + ";" + y + ";" + x + ";" + w + ";");
            Random kickassRNG = new Random();
            double rDOne = kickassRNG.nextDouble() * 90.0;
            double rDTwo = kickassRNG.nextDouble() * 90.0;
            System.out.println("rDOne= " + rDOne);
            System.out.println("rDTwo= " + rDTwo);
    //NOTE-EVERYTHING WORKS FINE UNTIL THIS POINT...
            if (rDOne > rDTwo)
            System.out.println("The larger of the 2 degs. is rDOne");
            //compute ceiling.
            double a=rDOne; //Store the value of rDOne.
            public static double ceil(double a);
            return a;
            System.out.println( "the ceiling of rDOne is " + a );
            //convert degree measurement to radians.     
            public static double toRadians(double b);
            double b = a;
            System.out.println("rDOne in radians is " + b );
            //compute tangent of that result.
            public static double tan(double c);
            double c = b;
            System.out.println("The tangent of rDOne is " + c );
            else
            System.out.println("The larger of the 2 degs. is rDTwo");
            //compute ceiling.
            double a=rDTwo; //Store the value of rDOne.
            public static double ceil(double a);
            return a;
            System.out.println( "the ceiling of rDTwo is " + a );
            //convert degree measurement to radians.     
            public static double toRadians(double b);
            double b = a;
            System.out.println("rDTwo in radians is " + b );
            //compute tangent of that result.
            public static double tan(double c);
            double c = b;
            System.out.println("The tangent of rDTwo is " + c );
        } //end main method.
    }

    VERY useful link..thxYou're welcome. Here are some more:
    Sun's basic Java tutorial
    Sun's New To Java Center. Includes an overview of what Java is, instructions for setting up Java, an intro to programming (that includes links to the above tutorial or to parts of it), quizzes, a list of resources, and info on certification and courses.
    http://javaalmanac.com. A couple dozen code examples that supplement The Java Developers Almanac.
    jGuru. A general Java resource site. Includes FAQs, forums, courses, more.
    JavaRanch. To quote the tagline on their homepage: "a friendly place for Java greenhorns." FAQs, forums (moderated, I believe), sample code, all kinds of goodies for newbies. From what I've heard, they live up to the "friendly" claim.
    Bruce Eckel's Thinking in Java (Available online.)
    Joshua Bloch's Effective Java
    Bert Bates and Kathy Sierra's Head First Java.
    James Gosling's The Java Programming Language. Gosling is
    the creator of Java. It doesn't get much more authoratative than this.

  • Invoking methods via java.lang.Method.invoke().

    I need to invoke the getter methods that I have defined for a Trade object passed as an argument.
    I am getting the excepion : java.lang.IIlegalArgumentException: wrong number of arguments.
    This is the first time I am invoking methods this way.
    Am I correct to assume that methods on an object can be invoked in this way?
    How can I invoke the getter methods of the trade object.
    Please help.
    public void displayData(Trade trade){
         Method[] m = trade.getClass().getMethods();
         for(int i=0;i<m.length;i++){
              if(m.getName().startsWith("get")){
                        try {
                             m[i].invoke(trade, new Trade[] { trade });
                        } catch (IllegalArgumentException e) {
                             e.printStackTrace();
                        } catch (IllegalAccessException e) {
                             e.printStackTrace();
                        } catch (InvocationTargetException e) {
                             e.printStackTrace();

    bhuru_luthria wrote:
    The getter methods of the trade object require no arguments.
    The three getter methods of the trade object are:
    getTradeId();
    getProductId()
    getReferenceId()Read the Javadoc; use it like this:
    m.invoke(trade);                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Java/lang/Runtime exception

    java.lang.RuntimeException: IOException reading reader invalid byte 1110011 error caused while running sun Wireless tool kit.Can any body please help me to solve this problem. I am using Eclipse 3.3 and also eclipse 3.2
    with sun java wireless toolkit in ubuntu.
    Thanks and Regards,
    Pandian

    Support for the RecipeFox extension is over here: <br />
    http://recipetools.sourceforge.net/phpBB3/index.php

  • Using java.lang.Float.class causing Cannot format given Object as a Number

    hi,
    I have table and its model is default table model.
    model = new javax.swing.table.DefaultTableModel(data,col) {Class[] types = new Class [] {
                    java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Float.class,  java.lang.Integer.class
                }; public Class getColumnClass(int columnIndex) {
                    return types [columnIndex];
                }};I want to force the user to enter float number to fourth column and integer number to fifth column. but I am gettin an error "Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Cannot format given Object as a Number" like this. cause of this error is "java.lang.Float.class". and when I use Integer instead of Float the is no problem. Could you please help ?

    It depends on model data.

  • Using java.lang.Math.sin/tan/cos  to make an arc - very simple

    hi all,
    i'm trying to dynamically create an set of numbers in an arch pattern -- going left to right (counter clockwise) --- from 0 degrees to 180 degrees. -- similar to an upside down U
    Any ideas on how i would do a simple loop to put the number 1 in a semicircle.
    I'm guessing that it might look like this
    while(x < 181)
    g.drawString(Integer.toString(x) , java.lang.Math.sin(..), java.lang.Math.cos(...) )
    how may I ask does that work again ?
    s

    The coordinates of the unit circle are given by
    x = cos(t)
    y = sin(t)
    where 0 < t <= 2pi
    You'll want to scale and translate that... Here's a code fragment; play with it a little:for (double t=Math.PI/2; t < 2*Math.PI, t += .05) {
        double x = 100*Math.cos(t) + 100;
        double y = 100*Math.sin(t) + 100;
        g.drawLine((int) x, (int) y, (int) x, (int) y);
    }

  • Advantages,Dis-advantages,when and where -use java.lang.Void Wrapper  class

    Hi All,
    I like to know when and where to use the wrapper class java.lang.Void and when it is particulary needed.if anyone could give me some examples it will be better.
    Thanks in advance,
    Kathir

    I like to know when and where to use the wrapper class java.lang.VoidWhy? If you don't need it, you don't have to use it.
    and when it is particulary needed.It is needed when you want to represent the concept of a void return value.
    if anyone could give me some examples it will be better.
    Method wait = Object.class.getMethod("wait",null);
    if (wait.getReturnType() == Void.TYPE) {
      System.out.println("Object.wait() returns null");
    }

  • Java.lang.Runtime()

    I made a small addition program using 'C'. It accepts 2 no.s and produces the result.
    how can i send the 2 no.s to the C program? Here is the code i tried:
    Runtime r=Runtime.getRuntime();
    Process p=r.exec("add.exe");
    InputStream ios=p.getInputStream();
    OutputStream ops=p.getOutputStream();
    String a="1\n", b="2\n", text;
    ops.write(a.getBytes());
    ops.write(b.getBytes());
    BufferedReader br=new BufferedReader(InputStreamReader(ios));
    while ( (text=br.readLine())!=null)
          System.out.println(text);I'm neither getting any output nor any error. What do i do? Plz help and thanks in advance.

    Maybe this time:
    ops.write(a.getBytes());
    ops.write(b.getBytes());
    ops.flush();
    [/code[                                                                                                                                                                                               

Maybe you are looking for

  • ISync and Motorola Razr2 V9 problem

    Hi all, I know there was a similar thread, but it's been archived so I can't post there. I just got a Motorola Razr2 V9x and tried to sync it with my Mac. I know I need a plugin for this. I have the plugin and iSync recognizes the phone. Whenever I t

  • Message app on osx keeps crashing before it can start up.

    i recently sent a very large message in the osx message app. now every time i click it it crashes and has a "application not responding". i have tryed restarting, dissabling airport and all that jazz but it does not work. i would like to know how to

  • SQL Tuning max + group by

    Hi all, I run this query select max(prelevement_dt), mpr from labo_demande group by mpr;The table labo_demande contains 1.688.883 rows and an index on (MPR, PRELEVEMENT_DT) exists. (I have already rebuilt this index). I gather stats on the table but

  • How to run a managed server on a different physical server?

    Hi, A) I have the following configuration: 1) Server A: Weblogic software with domain is installed. MachineA (ListenAddress=localhost, port=5556) NodeManager(port=5556) AdminServer (Uses MachineA, port=7001) ManagedServer01 (Uses MachineA, port-7002)

  • Adobe Muse CC Installation

    Adobe Application manager shows Muse CC installed and updated but it does not appear in applications or in a Sotlight search.