?
Solved

How to call Visual Basic .exe from Java?

Posted on 2003-03-10
2
Medium Priority
?
131 Views
Last Modified: 2011-09-20
Hello;

     Can anyone help how to call a visual basic exe file from a JButton, because I'd like to call my print software in my java program so that I could print my report, thanks . . .

0
Comment
Question by:Rosewell
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 8103108
You can use this:

import java.io.*;

public class RunAsync {

    public static void main(String args[]){

     try {
        Process pro = null;
        if (args.length > 0) {
          pro = Runtime.getRuntime().exec(args);
        }
        else {
          pro = Runtime.getRuntime().exec(args[0]);
        }
        InputStream error = pro.getErrorStream();
        InputStream output = pro.getInputStream();
        Thread err = new Thread(new OutErrReader(error));
        Thread out = new Thread(new OutErrReader(output));
        out.start();
        err.start();
        pro.waitFor();
     }
     catch(java.io.IOException e){
       e.printStackTrace();
     }
     catch(java.lang.InterruptedException e){
       e.printStackTrace();
     }

    }

    static class OutErrReader implements Runnable {
      InputStream is;

      public OutErrReader(InputStream is){
        this.is = is;
      }

      public void run(){
        try {
          BufferedReader in = new BufferedReader(new InputStreamReader(is));
          String temp = null;
          while((temp = in.readLine()) != null){
             System.out.println(temp);
          }
          is.close();
        }
        catch(Exception e){
          e.printStackTrace();
        }
      }
    }
}
0
 
LVL 2

Accepted Solution

by:
antonsigur earned 320 total points
ID: 8103301
...

JButton b = new JButton("Run application");

b.addActionListener(new myListener());

 ....


//The button listener
pirvare class myListener implements ActionListener {
  public void actionPerformed(ActionEvent ev) {
    try {
     Runtime.getRuntime().exec("yourprogram.exe");
     } catch(java.io.IOException e){
      e.printStackTrace();
    }
    catch(java.lang.InterruptedException e){
      e.printStackTrace();
    }
  }
}

Note, that you should give your points to CEHJ, I only implemented the raw listener...
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month12 days, 22 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question