How can I execute an external program from within a button's event handler?

I am using Tomcat ApacheTomcat 6.0.16 with Netbeans 6.1 (with the latest JDK/J2EE)
I need to execute external programs from an event handler for a button on a JSF page (the program is compiled, and extremely fast compared both to plain java and especially stored procedures written in SQL).
I tried what I'd do in a standalone program (as shown in the appended code), but it didn't work. Instead I received text saying the program couldn't be found. This error message comes even if I try the Windows command "dir". I thought with 'dir' I'd at least get the contents of the current working directory. :-(
I can probably get by with cgi on Apache's httpd server (or, I understand tomcat supports cgi, but I have yet to get that to work either), but whatever I do I need to be able to do it from within the button's event handler. And if I resort to cgi, I must be able to maintain session jumping from one server to the other and back.
So, then, how can I do this?
Thanks
Ted
NB: The programs that I need to run do NOT take input from the user. Rather, my code in the web application processes user selections from selection controls, and a couple field controls, sanitizes the inoputs and places clean, safe data in a MySQL database, and then the external program I need to run gets safe data from the database, does some heavy duty number crunching, and puts the output data into the database. They are well insulated from mischeif.
NB: In the following array_function_test.pl was placed in the same folder as the web application's jsp pages, (and I'd tried WEB-INF - with the same result), and I DID see the file in the application's war file.
        try {
            java.lang.ProcessBuilder pn = new java.lang.ProcessBuilder("array_function_test.pl");
            //pn.directory(new java.io.File("K:\\work"));
            java.lang.Process pr = pn.start();
            java.io.BufferedInputStream bis = (java.io.BufferedInputStream)pr.getInputStream();
            String tmp = new String("");
            byte b[] = new byte[1000];
            int i = 0;
            while (i != -1) {
                bis.read(b);
                tmp += new String(b);
            getSelectionsDisplayTextArea().setText(getSelectionsDisplayTextArea().getText() + "\n\n" + tmp);
        } catch (java.io.IOException ex) {
            getSelectionsDisplayTextArea().setText(getSelectionsDisplayTextArea().getText() + "\n\n" + ex.getMessage());
        }

Hi Fonsi!
One way to execute an external program is to use the System Exec.vi. You find it in the functions pallet under Communication.
/Thomas

Similar Messages

  • How Can I execute an external program from my vi?

    Hi guys,
    I want to execute a external program to use it when i called with a bottom. I want push a bottom and execute the program, like acess direct icon or so.
    Any help?.

    Hi Fonsi!
    One way to execute an external program is to use the System Exec.vi. You find it in the functions pallet under Communication.
    /Thomas

  • How can I run an external program from a PLSQL procedure?

    Is there a package to run an external program from PLSQL? or is there another way to do that?
    thanks.

    here there is an example about how a PL/SQL procedure can
    work with an external C program.
    http://download-east.oracle.com/docs/cd/A87860_01/doc/appdev.817/a76936/dbms_pi2.htm#1003384
    Apart from that you have Java Stored Procedures option
    to carry out your task.
    Java Stored Procedures Developer's Guide Contents / Search / Index / PDF
    http://download-east.oracle.com/docs/cd/B10501_01/java.920/a96659.pdf
    Joel P�rez

  • How can I execute a java program from a Servlet?

    Thank You
    [email protected]

    You could call it via Runtime.exec(), just as you would from any Java program. Or better, you could redesign it as a proper Java class. Then your servlet could create an instance of the class and call its methods as necessary.

  • How can native executable files be started from within a Java application.

    Hi Everyone,
    I am currently working on an application that will have the ability to start a program within Windows. What I intend on having is a button within my GUI that can start Microsoft Word. I am completely lost as to where I should begin in order to make this work. If anybody has any pointers they will be greatly appreciated. Thanks.
    Regards
    D

    Hi ,
    easy:
    Runtime.getRuntime().exec(new String[]{path,name});
    see:
    http://java.sun.com/j2se/1.3/docs/api/java/lang/Runtime.html
    HTH

  • How to execute a Perl program from within a Java prog

    How do I execute a Perl program from within a Java program.
    Lets say the Perl program that I want to execute is 'abc'. Now, 'abc' requires some input that I want to give it from within the Java program. How do I do it?
    And finally, how do I execute that Perl program from within the Java program.
    If I execute the Perl program alone then I do it in the following way -
    perl abc inp1 inp2 inp3
    where inp1, inp2, inp3 are inputs to the Perl program. I will not be able to change or modify the coding of the Perl program - 'abc' as I do not have access to its code. Its a kind of an application whose usual method of execution is in the above shown way. So, how do I execute 'abc' from within a Java program.

    what part of don't crosspost, don't you understand?
    http://forum.java.sun.com/thread.jsp?forum=4&thread=427193

  • Executing a Perl program from within a Java prog

    How do I execute a Perl program from within a Java program.
    Lets say that the Perl program that I want to execute is 'abc'.'abc' requires some input that I want to give from within the java program. How do I do that? Then I want to execute the Perl program from within the Java prog. How do I do it?

    don't crosspost.
    http://forum.java.sun.com/thread.jsp?forum=31&thread=427211&tstart=0&trange=100

  • How to call Operating System commands / external programs from within APEX

    Hi,
    Can someone please suggest how to call Operating Systems commands / external programs from within APEX?
    E.g. say I need to run a SQL script on a particular database. SQL script, database name, userid & password everything is available in a table in Oracle. I want to build a utility in APEX where by when I click a button APEX should run the following
    c:\oracle\bin\sqlplusw.exe userud/password@database @script_name.sql
    Any pointers will be greatly appreciated.
    Thanks & Regards,

    Hi Guys,
    I have reviewed the option of using scheduler and javascript and they do satisfy my requirements PARTIALLY. Any calls to operating system commands through these features will be made on the server where APEX is installed.
    However, here what I am looking at is to call operating systems programs on client machine. For example in my APEX application I have constructed the following strings of commands that needs to be run to execute a change request.
    sqlplusw.exe user/password@database @script1.sql
    sqlplusw.exe user/password@database @script2.sql
    sqlplusw.exe user/password@database @script3.sql
    sqlplusw.exe user/password@database @script4.sql
    What I want is to have a button/link on the APEX screen along with these lines so that when I click that link/button this entire line of command gets executed in the same way it would get executed if I copy and paste this command in the command window of windows.
    Believe me, if I am able to achieve what I intend to do, it is going to save a lot of our DBAs time and effort.
    Any help will be greatly appreciated.
    Thanks & Regards,

  • How can we disable the 'Improvement Program' from all the apps in TCS5?

    How can we disable the 'Improvement Program' from all the apps in TCS5, so that the end users are not able to see the option in the help menu?
    We have tried changing the value of bUsageMeasurement (HKLM\SOFTWARE\Policies\Adobe\(product name)\(version)\FeatureLockdown) to zero, but it did not help.

    You’re probably going to have to contact Support on that one.

  • How can I run an external program without quitting Firefox?

    I want to run an external program from within Firefox, much as Outlook express is run from the email button. How do I set this up?
    Firefox doesn't import my Bookmarks from the listed html file. Any cure for this?

    I don't want to run the mail program, I want to run another program.
    Maxthon allows me to do this using External Tools. Does Firefox allow me to run other programs without leaving Firefox?
    2. Firefox allows me to load an html file which contains my bookmarks, but it doesn't load the bookmarks file. is there a solution?

  • How can I import an m4v movie from my desktop to my event Library in iMovie?

    How can I import an m4v movie from my desktop to my event Library in iMovie?  I want to include the m4v movie into another project in iMovie.

    When you import DV Stream from tape, iMovie 11 will assume that you are importing raw footage from a camera, rather than a finished movie. It will create a new clip everytime it detects a scene break (the record start/stop button was pressed). These clips will be placed in chronolgical order - not the order they were on the tape.
    One way around this is to import the tape into the application that you used to create it. For example, if you used iMovie 6, import the tape back into imovie 6. In iMovie 6, you can export the tape back out using FILE/EXPORT USING QUICKTIME. Choose the DV codec in an MOV container.  You can then import this MOV file into iMovie 11 and have everything in the proper order for your finished movie.
    Another option is to use FInal Cut Pro X.

  • How can I execute a batch file from my java program

    Hi,
    Can someone help me or direct me to a link,
    How can I execute a DOS batch file from my java program?
    Thanks

    You will need to grab a handle to the process's
    outputstream so u can see its output.The OP didn't mention any output from any batch file;
    nor any input for that
    matter,so lets not complicate matters here for now
    ok?Actually I think this is essential to see whether it works or not. It's either that or do some manual check to see whether it ran, which is not exactly elegant, and in some cases this may not be easier than simply writing the output stream code, or in fact it may be impossible to check manually.
    I'm sure it wasn't intentional that your post appeared to be bristling with attitude.

  • Calling external programs from within a Tomcat application

    I've got a fairly complex existing Tomcat application (which is packaged and built as a .war file) which I'm trying to edit so that it calls a Perl script part way through the processing, which will generate an XML file used later on. I think I've worked out how to call external scripts from within Java, but at the moment when I try and access the application via Tomcat the application either hangs or bails out (I don't know which, as the log files unhelpfully don't give any error messages).
    The code which is causing the problem looks like this:
    System.err.println("Calling runtime...");
    Runtime runtime = Runtime.getRuntime();
    System.err.println("Executing process...");
    Process process = runtime.exec("/path/to/ysearch.pl 'News' '\"search query\"' 'file");
    System.err.println("Waiting for process...");
    int exitVal = process.waitFor();
    System.out.println("Exited with error code: " + exitVal);The code gets as far as "Executing process..", beyond that there is nothing in the log file so I presume the runtime.exec() call is where the problem is. I'm not interested in reading the output from the script (there shouldn't be any), so that's not an issue, and the permissions on it allow anyone to read or execute ysearch.pl so I don't think there's a problem in that area.
    Does anyone have any suggestions which I could try to get this to work? I've only been using Tomcat for a week (I'm picking up on someone else's code) so I might have made a beginner's mistake. I'm using Tomcat 5 on Fedora Core 7, and Java 1.5.0_01 (I can't easily change any of those).

    I'm not sure, but I thing that overhead caused by calling du cannot be big enough to matter even on older machines.
    But, when calling du from Perl script you are also invoking shell, and this can be a little bit more 'heavy'.

  • How can I get FINAL DRAFT program from MAC to a PC

    I tried the partition thing on external western digital drive,and it didn't work.
    Am trying to get the program of Final Draft, the
    program or whole folder, from macbook pro
    to send it to a pc netbook with windows starter 7.
    How can you do this??
    I saved it on a file sharing site and downloaded
    it but it didn't open.
    I don't have the instalation
    cd of the program so that *****. If you know please
    let me know, thanks very much.
    There has to be an easy way??

    Hi and welcome to Discussions,
    you cannot install WIndows with BootCamp on external harddisks.
    You cannot use an OSX application in Windows.
    The Terms of Use for the Apple Discussions Forum forbid us to:
    1. No material may be submitted that is intended to promote or commit an illegal act.
    2. Do not submit software or descriptions of processes that break or otherwise ‘work around’ digital rights management software or hardware. This includes conversations about ‘ripping’ DVDs or working around FairPlay software used on the iTunes Store.
    3. Do not post defamatory material.
    Regards
    Stefan

  • How can I run a perl program from XPRESS?

    Hellos..
    Java it seems has no concept of file permissions and ownership.
    Our handbuilt IDM XML file output adapter create files OK but they seem to be owned and have default permissions of root the account that kicks off the App Server.
    We want these XML files our resource adapter (written in java) creates to be accessible by a noshell account so it can get them with scp.
    The easiest way I thought was to have a little perl script in the mix. Must I really exec() `chmod` and `chown` ?
    I notice there is the <script> </script> for javascript 'coding'... when do we get a <perl> </perl> interface for doing useful things?
    GF

    here there is an example about how a PL/SQL procedure can
    work with an external C program.
    http://download-east.oracle.com/docs/cd/A87860_01/doc/appdev.817/a76936/dbms_pi2.htm#1003384
    Apart from that you have Java Stored Procedures option
    to carry out your task.
    Java Stored Procedures Developer's Guide Contents / Search / Index / PDF
    http://download-east.oracle.com/docs/cd/B10501_01/java.920/a96659.pdf
    Joel P�rez

Maybe you are looking for