Running programs from within other programs

I have a problem with running small java-applications form within another.
If I put the BufferedReader for errors first, sometimes it gets stuck
(without throwing any exceptions) when I want to run applications that
are working without any errors, when I run them manually. But if I put
the standardoutput-Reader first, it gets stuck (again without throwing
any exceptions), when an error occurs. This "getting stuck" always happens
in the line where the "while" is. It seems that nothing can be read, but its
not null too.
Thats part of my code:
String cmd = "java -cp rightDirectory MyFile";
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(cmd);
BufferedReader pout = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
String line2;
while ((line2 = pout.readLine()) != null) {
System.out.println(line2);
pout.close();
BufferedReader peout = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line;
while ((line = peout.readLine()) != null) {
System.out.println(line);
peout.close();
How can this be done, that it works for all cases?

hi, Have you read http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html ?

Similar Messages

  • Running ssh from within java program

    Hi!
    I am trying to start ssh from within java e.g.:
    Runtime run = Runtime.getRuntime();
    Process pro = run.exec("ssh -l xx 12.12.12.12");
    But it complains:
    socket: Operation not permitted
    ssh: connect to host 12.12.12.12 port 22: Operation not permitted
    Running ssh from the command prompt works just fine. It's run on win xp.
    What is the problem, and how can I avoid it?
    Endre

    Afraid not. I think maybe it's related to security permissions, but I am really not sure. If you can help, I would appreciate it.
    - Endre

  • How can we call creen of one program from some other dynpro Program

    Hi,
    Is it possible to call a screen of one program from some other program as pop up or full scree.
    please give you input if it is possible.
    Thanks in advance.
    Thanks and Regards,
    Praveen.

    Hi,
    But is there is any function module through we can call screen of some other program. PLease let me know if you are aware of that.
    Thanks

  • 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,

  • Creating a Step for Background Job from within ABAP Program

    Step-1: I have a Report in ECC, which is scheduled as Background Job, which writes the file to the Application Server(UNIX)
    Step-2:  Trigger a Unix Command to ftp the file to other server.
    Both Step-1 & Step-2 can be done from SM36. 
    Another Scenario:
    Users can run the report in background from SE38 or using the transaction code for the report, In this case we want to call the external command.
    Instead of calling the External Command as below in the report, I want to create a Step from within the program when it is scheduled in background mode.
    CALL 'SYSTEM' ID 'COMMAND' FIELD lc_unixcom.    [ Here lc_unixcom has the External Command ].
    Any ideas??? Appreciate help.

    Hi,
    For submitting a report step, you may use either SUBMIT ... VIA JOB ... or JOB_SUBMIT function module.
    For external commands, this should be done only by calling JOB_SUBMIT function module.
    Sandra

  • I have CS 6 installed on a Win 7 OS machine. I can not connect to the internet to get updates from within the program. How do I fix this?

    I have CS 6 installed on a Win 7 OS machine. I can not connect to the internet to get updates from within the program. How do I fix this?

    IP routing doesn't work the way many folks might initially think it does; functional IP routing requires manual configuration and the establishment of static routes and default routes specific to the local network configurations, and it's very easy to get it wrong, or to get the default route swapped. Multiple NIC boxes don't magically work, either. (Been there, done that, wondered what happened to my network when the paths got reordered or my route settings were messed up, etc.)
    Routing configuration errors can be quite subtle, too. (Again, voice of experience. Ever had a thousand-seat office LAN accidentally routing through your desktop? As the, um, unnamed guilty party discovered, getting into that configuration was subtle. Seeing the performance crater on the fellow's box and on the LAN was obvious.)
    Knowing how IP routing works is a prerequisite to getting this configuration to work; there's manual configuration required. Clearly something has gone weird here.
    What to do? Read up on IP routing. I'll again suggest the threads and the manual mentioned earlier.
    And in general, I prefer to avoid using my comparatively expensive Mac boxes as sub-optimal IP routers or as firewall boxes. General-purpose operating systems and generic x86 boxes are going to be inherently poor IP routers. Dedicated routers (or embedded or surplus x86 boxes with routing software loaded) offload the Mac boxes here, and are also typically easier to configure manage. And "real" IP routers can have hardware specific to efficiently routing packets. Use of an outboard firewall or firewall-router box also greatly simplifies gateway routing, too; it's a configuration that many folks and many businesses tend to use.

  • Cannot print to Adobe Acrobat X from any other program

    I recently installed Acrobat X on my Windows XP3 system.  Previously, the Adobe Printer installed by the Acrobat 8 was accessible from any other program.  I simply chose the Adobe PDF printer and the documents "printed" to Acrobat.  With the Acrobat X install, this no longer works.
    I've tried repairing the Acrobat X - no luck
    I've tried deleting the Adobe PDF printer and then allowing Acrobat to re-install the printer during the repair - no luck
    I've checked the Adobe PDF printer properties, and do not have "Enable advanced printing features" checked.
    I am using the print spooler.
    The Adobe PDF printer is using the Adobe PDF Converter driver.
    I've read through a number of discussions/posts, and have not found a solution.  I am working around the problem by printing to pdfFactory program and then saving as a .pdf, then managing the files in Acrobat X.
    If anyone is aware of a solution/location, please respond to this post.   

    Are you saying there is no Adobe PDF printer, or it does not work? If it simply that it does not seem to work, then try to print to file with the printer. Then open the file in Distiller. If you get a resultant PDF, then the problem is most likely that you have somehow deactivated AcroTray.exe in the running applications. The program is in the Acrobat folder and needs to be started in that case. It should also be listed in your boot sequence for startup.

  • 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

  • What is going on?  I can't access my iPhoto files from any other programs.  It just says "Open iPhoto to see photos from your iPhoto Library in this list", but that doesn't work.  What changed?

    All of a sudden I can't access my iPhoto files from any other programs (ie Photoshop, facebook etc.).  It just gives me this message below.  What the **** changed?  This wasn't happening yesterday.

    1 - close iPhoto.
    2 - go to your Pictures folder and open the iPhoto Library package as shown below:
    3 - locate a file named AlbumData.xml and move it to the Desktop.
    4 - launch iPhoto.
    5 - relaunch the other programs and try the media browser again.
    OT

  • Execute a java program from an another program

    Like we can compile a code from wihin a java file by using the following :
    Tool javac = ToolProvider.getSystemJavaCompiler();
    Similarly,can we execute i.e. run a java program from within a java file i.e. running d java command from within the java file ??If yes then please tell me how??

    suppose on the Unix box or from a Unix script ( korn, perl, bourne, bash) you can run the following java program
    java ${JAVA_OPTS} -jar ${GMR_APPS_DIR}/risk.jar -I -c ${COB} -r ${BATCH} -o ${XML_DIR}
    in java you can do the following :
    Runtime rt = Runtime.getRuntime();
              try {
                   Process process = rt.exec("java ${JAVA_OPTS} -jar ${GMR_APPS_DIR}/risk.jar -I -c ${COB} -r ${BATCH} -o ${XML_DIR}
    // OR
                   Process process = rt.exec("/export/apps/Tools/apache-tomcat-5.5.17/bin/startup.sh");
                   // process.destroy(); if you want to kill the process
                   process.waitFor();
                   int RC = process.exitValue();      
                   System.out.println(returnOutput(process.getErrorStream()));
                   System.out.println(returnOutput(process.getInputStream()));
              } catch (Exception ex) {
                   ex.printStackTrace();
    empty the output stream from the script
    private String returnOutput(InputStream is) throws Exception {
                   String s;
                   StringBuffer strBuff = new StringBuffer();
                   BufferedReader br = new BufferedReader(new InputStreamReader(is));
                   while ((s = br.readLine()) != null) {
                        strBuff.append(s);
                   return strBuff.toString();
              }You need to relace the ${} by the appropriate values.
    Regards,
    Alan Mehio
    London, UK
    Edited by: alan_mehio on Jan 16, 2008 4:21 PM

  • Programming to call other programs

    I am in need of direction as I am unable to find any help on my current problem. I am developing a program that will create a database of triples from an xml document. My use of existing programs such as 4suite's '4rdf' which is called by the command prompt has left me with the issue of how do you program in java, to call other programs and/or the command line. I need to pass in arguments and execute the program from within one java program. Is this possible? Help is urgently required. Please help. Cheers Dave.

    Allways happy to assist my follow programmers, this is a class I developed (with help from online documents of course) to contain all my executing needs. Note that you need to place these two classes in a package yourself, they are part of quite a complex one where I use them.
    public class Semaphore {
      protected boolean blocked;
      public Semaphore() { blocked = false; }
      public synchronized void waitUntilSignalled() {
           if(blocked == false){
             try {
                    blocked = true;
                    wait();
                } catch(  InterruptedException e ) { }
      public synchronized void setSignalled() {
        if (blocked == true){
              blocked = false;
              notifyAll();
         public static class ExecStreamThread extends Thread
             InputStream is;
             OutputStream os;
             Semaphore sem;
             public ExecStreamThread(InputStream is, OutputStream redirect)
                 this.is = is;
                 this.os = redirect;
                 sem = null;
             public ExecStreamThread(InputStream is, OutputStream redirect, Semaphore theSem)
                 this.is = is;
                 this.os = redirect;
                 sem = theSem;
             public void run()
                  try
                       PrintWriter pw = pw = new PrintWriter(os);
                       InputStreamReader isr = new InputStreamReader(is);
                       BufferedReader br = new BufferedReader(isr);
                       String line=null;
                       while ( (line = br.readLine()) != null)
                                pw.println(line);
                           pw.flush();
                  } catch (IOException ioe){
                      // don't have to do anything, the parent thread will have found out the process errored
                  // run is complete, signal the semaphore
                  if(sem != null){
                       sem.setSignalled();
         public static final int OSTYPE_WINDOWS = 1;
         public static final int OSTYPE_WINNT = 2;
         public static final int OSTYPE_WINCE = 3;
         public static final int OSTYPE_LINUX = 4;
         public static final int OSTYPE_MAC = 5;
         public static final int OSTYPE_SOLARIS = 6;
         public static final int OSTYPE_NETWARE = 7;
         public static final int OSTYPE_OS2 = 8;
         public static final int OSTYPE_UNKNOWN = 9;
         private static int type = OSTYPE_UNKNOWN;
         private ExecUtil()
              @return an integer identifying the OS (one of the OSTYPE constants)
         public static int getOs()
              if(type == OSTYPE_UNKNOWN){
                   String osname = System.getProperty("os.name").toLowerCase();
                   if(osname.indexOf("windows") != -1){
                        if(osname.indexOf("nt") != -1 || osname.indexOf("2000") != -1 || osname.indexOf("xp") != -1){
                             type = OSTYPE_WINNT;
                        } else if(osname.indexOf("ce") != -1){
                             type = OSTYPE_WINCE;
                        } else {
                             type = OSTYPE_WINDOWS;
                   } else if(osname.indexOf("linux") != -1 || osname.indexOf("bsd") != -1){
                        type = OSTYPE_LINUX;     
                   } else if(osname.indexOf("mac os") != -1 || osname.indexOf("macos") != -1){
                        type = OSTYPE_MAC;
                   } else if(osname.indexOf("solaris") != -1){
                        type = OSTYPE_SOLARIS;     // could also be old freebsd version
                   } else if(osname.indexOf("netware") != -1){
                        type = OSTYPE_NETWARE;
                   } else if(osname.indexOf("os/2") != -1){
                        type = OSTYPE_OS2;
                   } else {
                        type = OSTYPE_UNKNOWN;     
              return type;
              @return the prefix to execute a shell command. For example "command /c " to execute a shell command on windows9X machines.
         public static String getShellString()
                 String appendStr = "";
                 int ostype = getOs();
                 if(ostype == OSTYPE_WINDOWS){
                      appendStr = "command /c ";
                 } else if(ostype == OSTYPE_WINNT || ostype == OSTYPE_WINCE){
                      appendStr = "cmd /c ";     
                 } else if(ostype == OSTYPE_LINUX || ostype == OSTYPE_MAC){
                      appendStr = "/bin/sh -c ";     
                 } // add other shell executers
                 return appendStr;
         /** execute a command and ignore any output it generates (output is sent to System.out and System.err).
              It is valid to pass a command containing multiple parameters
              @param command the command to execute
              @return the exit code the process generated
         public static int exec(String command)
              throws IOException
              return exec(command, false, System.out, System.err);
         /** execute a (shell) command and ignore any output it generates (output is sent to System.out and System.err).
              It is valid to pass a command containing multiple parameters.
              NOTE: only windows (command), winnt (cmd) and linux (sh) shell executions are supported.
              @param command the command to execute
              @param shellCommand should the command be handled as an internal shell command?
              @return the exit code the process generated
         public static int exec(String command, boolean shellCommand)
              throws IOException
              return exec(command, shellCommand, System.out, System.err);
         /** execute a (shell) command and catch the output it generates.
              It is valid to pass a command containing multiple parameters.
              NOTE: only windows (command), winnt (cmd) and linux (sh) shell executions are supported.
              @param command the command to execute
              @param shellCommand should the command be handled as an internal shell command?
              @param output the output stream to send the output of the process to (output is handled as textual data)
              @return the exit code the process generated
         public static int exec(String command, boolean shellCommand, OutputStream output)
              throws IOException
              return exec(command, shellCommand, output, System.err);
         /** execute a command and catch the output it generates.
              It is valid to pass a command containing multiple parameters.
              @param command the command to execute
              @param output the output stream to send the output of the process to (output is handled as textual data)
              @return the exit code the process generated
         public static int exec(String command, OutputStream output)
              throws IOException
              return exec(command, false, output, System.err);
         /** execute a command and catch the output (stdout) and errors (stderr) it generates.
              It is valid to pass a command containing multiple parameters.
              @param command the command to execute
              @param output the output stream to send the output of the process to (output is handled as textual data)
              @param error the output stream to send the error output of the process to (output is handled as textual data)
              @return the exit code the process generated
         public static int exec(String command, OutputStream output, OutputStream error)
              throws IOException
              return exec(command, false, output, error);
         /** execute a command and catch the output (stdout) and errors (stderr) it generates.
              It is valid to pass a command containing multiple parameters.
              NOTE: only windows (command), winnt (cmd) and linux (sh) shell executions are supported.
              @param command the command to execute
              @param shellCommand should the command be handled as an internal shell command?
              @param output the output stream to send the output of the process to (output is handled as textual data)
              @param error the output stream to send the error output of the process to (output is handled as textual data)
              @return the exit code the process generated
         public static int exec(String command, boolean shellCommand, OutputStream output, OutputStream error)
              throws IOException
             if(shellCommand == true){
                  String appendStr = getShellString();
                  command = appendStr + command;
             String[] realcommand;
             if(command.indexOf(" ") != -1){
                  realcommand = command.split(" ");
             } else {
                  realcommand = new String[1];
                  realcommand[0] = command;     
             try{
                  Process ls_proc = Runtime.getRuntime().exec(realcommand);
                   ExecStreamThread execOutput;
                   ExecStreamThread execError;
                   execOutput = new ExecStreamThread(ls_proc.getInputStream(), output);
                   execOutput.start();
                   execError = new ExecStreamThread(ls_proc.getErrorStream(), error);
                   execError.start();
                 int exitvalue = ls_proc.waitFor();     
                   if(output != null) { output.flush(); }
                   if(error != null) { error.flush(); }
                   return exitvalue;
              } catch(Exception e){
                   throw new IOException(e.getMessage());
         public static void main(String[] args)
              try{
                   int code = ExecUtil.exec("javac test.java", System.out, System.err);
                   System.out.println("Exit code was : " + code);
                   code = ExecUtil.exec("java test", System.out, System.err);
                   System.out.println("Exit code was : " + code);
              } catch(IOException e){
                   System.out.println("failed due to exception: " + e);
              try{
                   int code = ExecUtil.exec("dir/w", true, System.out, System.err);
                   System.out.println("Exit code was : " + code);
              } catch(IOException e){
                   System.out.println("failed due to exception: " + e);
    }

  • Calling another program from the current program

    Hi all,
    In our requirement we are calling another program from our current program .
    In the current program( from which we are calling ) we are giving file name in the selection screen
    and when we run the current program we are successfully going to other program but our main requirement is to higlight the file name which we had given earlier .
    Note :  The called program doesnt have any selection screen.

    HI
    use EXPORT and IMPORT key words for passing data from one program to another program.
    as the called program is available in the same session you can use above key words which means you are accessing ABAP MEMORY.
    You can also use SET and GET key words which means SAP memory
    take F1 help there are examples tooo and detailes explanation abou the same
    Regards
    Ramchander Rao.K
    Edited by: Ramchander Krishnamraju on Dec 24, 2008 7:05 AM

  • Spawning child program from parent concurrent program.

    Hi All,
    I am trying to spawn multiple child programs from Parent concurrent program, Parent concurrent program is having execution method as HOST.
    Here is how I designed it.
    1. Parent Concurrent program (Parent Conc program with execution method as HOST).
    2. Host file is abc.prog calls PLSQL package xyz.main.
    3. xyz.main has logic to launch multiple child programs - (Child Conc program with execution method as PLSQL stored proc) using fnd_request.submit_request utility.
    All the child programs are getting launched but are in INACTIVE/NOMANAGER state. Could you please let me know how to overcome this issue.
    Both Parent and child programs are added to standard concurrent manager. This issue is only coming when parent program as execution method as HOST if parent program execution method is PLSQL stored procedure then child programs are running fine..
    I also tired initializing apps in HOST file (abc.prog) before calling PLSQL package xyz.main.
    Thanks.
    Sham.

    hi,
    even i was facing the same issue. while submitting the child requests through fnd_request.submit_request i tried the following:
    FND_REQUEST.submit_request (
    application => 'Application Short Name',
    program => 'Program Executable Name',
    description => 'Program Description',
    start_time => NULL,
    sub_request => FALSE,
    argument1 => 'Input 1',
    argument2 => 'Input 2' );
    After this the Programs were submitted successfully.

  • Program  to list all include programs  from the  Sap program list

    My requirement is to display all include programs from the Sap program Table ( D010INC table and TADIR table), From
    here i have to get all include programs.Can anyone give the program code for this requirement

    well, it's your requirement and not ours, so why not try yourself first?

Maybe you are looking for

  • How to go back to mountain lion from mavericks

    What's the easiest way to revert back to Mountain Lion from Mavericks? I'm having troubles using Final Cut Pro X on Mavericks

  • Database Transaction

    Hi, In our project we have EJB's(CAS) consumed in CAS. The EJB's communicate with SQL/Oracle DB's through standard queries(insert, update etc). Now we want to implement "Database Transaction" i.e, if the any one user from front-end is accessing the p

  • Not compatible with speaker since update to 3.1 (and other issues)

    I have an Altec-Lansing T612 speaker that I specifically bought because it was advertised as "works with iPhone". No problems until I recently updated the phone's OS. Now when I put the iPhone in the speaker dock, I get the message "this device is no

  • Bounding box and 3D

    I have an issue with getting movieclip's bounding box when it has nonzero z-property. Here's the example of code producing correct result shown on figure A: var m : Meat = new Meat(); addChild(m); m.x = 100; m.y = 100; m.z = 100; m.rotationY = 45; va

  • CGIServlet/Perl can't seem to find my package

    I am running WLS6.0 and configured the CGIServlet to run some Perl scripts. I have some of my code in a package (common.pm) and that package file is in the same directory as my perl scripts. I can't seem to get any of the scripts to work that use my