Running a perl shell command through a java program on linux platform

i'm trying to execute the following command in a java program "perl xxx.pl" using the runtime.getruntime method
here is the piece of code
String[] cmd={"perl","-c","AraMorph.pl",""};
Process p = Runtime.getRuntime().exec(cmd,null,new File("/home/ahmed/buckwalter_morphan_1/data"));
p.waitFor();
BufferedReader in=new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line=in.readLine())!=null)
System.out.println(line);
but it doesn't output anything even if i tried to print the output to a file
i'm trying to execute this program on linux platform but its working properly on a windows platform
thx
raar

String[] cmd={"perl","AraMorph.pl"," </home/ahmed/in.txt"," >/home/ahmed/ast.txt"};
Process p = Runtime.getRuntime().exec(cmd,null,new File("/home/ahmed/buckwalter_morphan_1/data"));
BufferedReader in=new BufferedReader(new InputStreamReader(p.getErrorStream()));
String line;
while ((line=in.readLine())!=null)
System.out.println(line);
p.waitFor();
String str2=p.getInputStream().toString();
System.out.println("==================================="+str2);
and it still outputs nothing but goes in something like infinite loop or as assumed in the article u suggested a deadlock but even all solutions to all pitfalls didn't succeed

Similar Messages

  • Running a DOS Command through a JAVA GUI

    I'm trying to run a command line through a GUI.. how would i go about doing this... suppose i wanted to run the following dos command inside a java program:
    String command = "jar cvf classes.jar open.java close.java"
    Does anyone have a good model I can look at that can implement a dos command?

    Maybe you can refer to this resource , I can not remember the Class, It seems like this Runtime.getRuntime().exec() ?? It can execute your command.

  • Question about Java implementation in Linux platform

    Hello,
    I shall implement one Java program in Linux platform. I'm a newer to linux. Need I install some special software in Linux platform to compile and run JAVA program?
    Thank you in advance
    java_linux

    Sorry, this forum is about Sun Studio, which is a collection of native compilers and tools. About Java, please use Java forum; for example, one of these: http://forums.sun.com/category.jspa?categoryID=5

  • How to execute unix command from the Java program running on Windows

    Hello,
    I need to
    1. Execute a unix shell script from a Java program running on the Windows.
    2. I also need to capture the output of this shell script in my program.
    Please suggest me how to achieve this.
    Thanks in Advance.

    Hi...
    Something is missing here
    If you want to execute a shell script in windows that not posible unless you find or develop a unix shell script parser for windows.
    But if you are trying the execute a unix shell script on a remote unix computer from your java program running on a windows platform you can do that by logging on to the UNIX terminal which is running on port 23 I think.
    You can test this using telnet tool on windows
    just type on command prompt
    telnet <ip of the unix pc> <port number this case 23>
    you should get the unix terminal. If that works you can do the same through java or you can directly conect to port 23 of that pc using sockets that way your program will be platform independant

  • Running curl command from a java program using Runtime.getRuntime.exec

    for some reason my curl command does not run when I run it from within my java program and errors out with "https protocol not supported". This same curl command however runs fine from any directory on my red hat linux system.
    To debug the problem, I printed my curl command from the java program before calling Runtime.getRuntime.exec command and then used this o/p to run from the command line and it runs fine.
    I am not using libcurl or anything else, I am running a simple curl command as a command line utility from inside a Java program.
    Any ideas on why this might be happening?

    thanks a lot for your response. The reason why I am using curl is because I need to use certificates and keys to gain access to the internal server. So I use curl "<url> --cert <path to the certificate>" --key "<path to the key>". If you don't mid could you please tell me which version of curl you are using.
    I am using 7.15 in my system.
    Below is the code which errors out.
    public int execCurlCmd(String command)
              String s = null;
              try {
                  // run the Unix "ps -ef" command
                     Process p = Runtime.getRuntime().exec(command);
                     BufferedReader stdInput = new BufferedReader(new
                          InputStreamReader(p.getInputStream()));
                     BufferedReader stdError = new BufferedReader(new
                          InputStreamReader(p.getErrorStream()));
                     // read the output from the command
                     System.out.println("Here is the standard output of the command:\n");
                     while ((s = stdInput.readLine()) != null) {
                         System.out.println(s);
                     // read any errors from the attempted command
                     System.out.println("Here is the standard error of the command (if any):\n");
                     while ((s = stdError.readLine()) != null) {
                         System.out.println(s);
                     return(0);
                 catch (IOException e) {
                     System.out.println("exception happened - here's what I know: ");
                     e.printStackTrace();
                     return(-1);
         }

  • How to run a openssl command from a java program

    Hi All
    Please suggest on how to run a openssl command from a java program.
    I am using this
    Runtime runtime = Runtime.getRuntime();
    runtime.exec("openssl pkcs8 -inform der -nocrypt test.der result.pem");
    This is suppose to take test.der as input and create result.pem.
    There are no errors but the file result.pem isnt created.
    Thanks in Advance

    First off is that openssl command correct? Should it be this instead:
    openssl pkcs8 -inform der -nocrypt -in test.der -out result.pem
    Try out your openssl command within a command prompt so that you know that it works ok. I think the command line you specified waits on stdin (well it does for me).
    After that.....
    runtime.exec creates a Process object. If you do this:
    Process openssl = runtime.exec("....")
    then you can examine the return code from openssl to see the exit code - for instance if the input file does not exist then exit = 1. You can test for this with Java
    Alternatively you could get the stderr from the process and look inside it - if it is 0 length then all is good, if it has some text in there then it has likely failed. You could then throw an exception and include the stderr output in the exception messgae. You may need to experiment with this, runnig it first when openssl is happy then running it again when openssl is upset.
    M

  • Running a Unix Script through a Java Program

    Hi !!!!!!!!! Can anybody plz suggest me an approach for the following queries -
    1.  How to execute a unix script through a java program ?
      2.  How to send the o/p of the script to a java program so that it can be used .

    import java.io.*;
    public RunScript
       public static void main(String args[])
          try
              Process p = Runtime.getRuntime().exec("script.sh");
              BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));     
              while ((line = input.readLine()) != null)
                 System.out.println(line);
              input.close();
          catch(Exception e)
              e.printStackTrace();

  • Invoking gdb through a Java program as subprocess

    Hi,
    I try to invoke the gdb through a java program using Runtime.exec(...)
    as a Process, I also try to get the output of gdb using InputStream object, Is there any way to provide the options to gdb when it is started as Process & also tracing it's output.
    please help Me.

    Have a read of
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-
    traps.htmlwhat ? I'm not sure what you are referring to with your 'what?' BUT that reference should be read by anyone using Runtime.exec().
    >
    the unix command such as
    tail xxxxxxxxxxxxxxxxxx
    and write it to a shell script,and invoke it by
    java,any problems?I don't agree with this. There is no need for a shell script. This would just add to the complexity without adding any extra functionality.
    >
    but sabre150 has give a good solutionThank you.

  • How to implement a print screen through a java program rather than a keyboa

    help needed urgently to make a college project.
    have to capture whatsoever is on the client screen
    and sent it to to a server program where it will be made visible on a frame or panel.
    this is to be done without the client ever knowing it.
    so needed to implement a printscreen command using java code and put it in a program(also how to make
    the .class file containing this code run in the background all the time since the client comp starts till it is shut down without the client ever knowing it)
    e mail: [email protected]

    <pre>
    hartmut
    i need help.
    i've recently started using the web to learn more about java.your reply was very discouraging.
    the proff. just wants a decent project.
    but i want to make this project to improve my java networking skills.
    if you can help , please tell me how to implement a printscreen through a java program rather than a keyboard.
    I'll be very grateful to you if you can help me in this regard, but please dont send a dissapointing response like the previous one.
    mail: [email protected]
    </pre>

  • Is there any way to close an IE browser on XP through a Java Program

    Hi All,
    I am working on an application which has a web form with various feilds in it, on selecting the fields and clicking submit, the form will launch a WinRunner application in a remote machine and runs a test. For this I am using Tomcat webserver (V4.0.1). Now the problem I have is, when I submit the form, and WinRunner Launches on the remote machine (which has Operating System XP), should not already have any Browser windows open on it. So, to ensure that no browser windows are open, Initially in my Java Program I want to write a code which cleans up all the OPEN Browser windows on that machine.
    Can any one help me out in finding a way of closing the IE browser windows on a XP machine through a Java program. (There is a servlet in the Tomcat webserver which launches the application based on the browser request). Tomcat is installed on the machine where WinRunner will be launched, So my browser request goes to that machine directly.
    Thank you very much,
    Ramesh Babu M.V.

    You can call some program (via Runtime.exec) that kills all IEXPLORE.EXE processes (ugly but could work for you). For instance, there is a program called kill.exe that you can try getting somewhere. My version of KILL.EXE is really old and somewhat buggy (killed all IEXPLORE.EXE processes but one in my Windows 2003 machine), so try checking if there's some newer version anywhere.
    C:\>kill -?
    Microsoft (R) Windows NT (TM) Version 3.5 KILL
    Copyright (C) 1994-1998 Microsoft Corp. All rights reserved
    usage: KILL [options] <<pid> | <pattern>>*
               [options]:
                   -f     Force process kill
               <pid>
                  This is the process id for the task
                   to be killed.  Use TLIST to get a
                   valid pid
               <pattern>
                  The pattern can be a complete task
                  name or a regular expression pattern
                  to use as a match.  Kill matches the
                  supplied pattern against the task names
                  and the window titles.

  • How:Execute OS commands from a Java program

    hi,
    is it possible to execute an OS command from a java program, as in C/C++? if yes, plz give the details.
    thanx

    In the future try searching the forum before posting. Using keywords like "execute os commands" would lead you to several postings on this topic.
    Note the keywords where taken directly from you subject line. With practice you learn which keywords to use to yield the best search results.

  • Procedure to call shell script which invoke java program

    Hi
    I have requirement for a pl/sql procedure to invokes a shell script which calls java programs.
    I was using DBMS_SCHEDULTER to invoke the shell , the shell is getting invoked but it is not executing the java programs.
    appreciate your suggestions and advices .
    param1=$1
    param2=$2
    #echo "First parameter is:"$1
    #echo "Param1 is:"$param1
    if [ $# -eq 1 ]; then
    java -jar -Xmx512m abc.jar ${CONFIG_DIR} $param1
    elif [ $# -eq 2 ]; then
    java -jar -Xmx512m abc.jar ${CONFIG_DIR} $param1 $param2
    fi
    Regards

    user458361 wrote:
    Hi
    I have requirement for a pl/sql procedure to invokes a shell script which calls java programs.
    I was using DBMS_SCHEDULTER to invoke the shell , the shell is getting invoked but it is not executing the java programs.
    appreciate your suggestions and advices .
    param1=$1
    param2=$2
    #echo "First parameter is:"$1
    #echo "Param1 is:"$param1
    if [ $# -eq 1 ]; then
    java -jar -Xmx512m abc.jar ${CONFIG_DIR} $param1
    elif [ $# -eq 2 ]; then
    java -jar -Xmx512m abc.jar ${CONFIG_DIR} $param1 $param2
    fi
    RegardsYou are doing the equivalent of making THREE Left turns instead of a single Right turn
    Most likely the shell environment is woefully lacking in needed details
    add new line as below
    param1=$1
    param2=$2
    /usr/bin/env | /usr/bin/sort -o /tmp/capture.log
    # make sure above Fully Qualified Pathnames are correct for your system!
    After you invoke script from PL/SQL post content of /tmp/capture.log back here

  • Linux shell commands through linux

    i am trying to run shell comands through java.
    so far i hav been success ful in running some of them. but when ever a '\' symbol is encountered it doesnt work.
    i use
    process p = Runtime.getRuntime().exec(command)
    example
    command= "mount -t smbfs //192.168.10.150/abcd /home/lan" works fine
    but "mount -t smbfs //192.168.10.34/english\\ songs /home/lan"
    does not work
    is there a way to bypass writing a shell script and executing it?
    i just want to execute it directly without writing it in a shell file first.

    yes there are spaces in the path name thats why im using '\'. and yes in the string i do write it as '\\'. it displays the correct path name using println in the terminal but doesnt run using exec(). im aware of the temp.sh way and i know it works but im working on a networking project and want to avoid writing to a file again and again.
    the other constructor of exec seems interesting. ill try it.

  • PROBLEM in executing a shell command through Runtime.getRuntime().exec()

    Hi all,
    I was trying to execute the following code:
    import java.io.BufferedReader;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.sql.CallableStatement;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.Statement;
    import java.sql.ResultSet;
    * Created on Mar 13, 2007
    * To change the template for this generated file go to
    * Window>Preferences>Java>Code Generation>Code and Comments
    * @author 195092
    * To change the template for this generated type comment go to
    * Window>Preferences>Java>Code Generation>Code and Comments
    public class ClassReportDeleteDaemon {
         ClassReportDeleteDaemon()
         public static void main(String[] args) throws Exception
              Connection conn = null;
              Statement stmt = null;
              ResultSet rs;
              String strQuery = null;
              String strdaysback = null;
              String delstring = null;
              int daysback;
              try
                   System.out.println("REPORT DELETION ::: FINDING DRIVER");               
                   Class.forName("oracle.jdbc.driver.OracleDriver");
              catch(Exception e)
                   System.out.println("REPORT DELETION ::: DRIVER EXCEPTION--" + e.getMessage());
                   System.out.println("REPORT DELETION ::: DRIVER NOT FOUND");
              try
                   String strUrl = "jdbc:Oracle:thin:" + args[0] + "/" + args[1] + "@" + args[2];
                   System.out.println("REPORT DELETION ::: TRYING FOR JDBC CONNECTION");
                   conn = DriverManager.getConnection(strUrl);
                   System.out.println("REPORT DELETION ::: SUCCESSFUL CONNECTION");
                   while(true)
                        System.out.println("WHILE LOOP");
                        stmt = conn.createStatement();
                        strQuery = "SELECT REP_DAYS_OLD FROM T_REPORT_DEL";
                        rs = stmt.executeQuery(strQuery);
                        while(rs.next())
                             strdaysback = rs.getString("REP_DAYS_OLD");
                             //daysback = Integer.parseInt(strdaysback);
                        System.out.print("NO of Days===>" + strdaysback);
                        delstring = "find /tmp/reports1 -name " + "\"" + "*" + "\"" + " -mtime +" + strdaysback + " -print|xargs rm -r";
                        System.out.println("DELETE STRING===>" + delstring);
                        Process proc = Runtime.getRuntime().exec(delstring);
                        //Get error stream to display error messages encountered during execution of command
                        InputStream errStream=proc.getErrorStream();
                        //Get error stream to display output messages encountered during execution of command
                        InputStream inStream = proc.getInputStream();
                        InputStreamReader strReader = new InputStreamReader(errStream);
                        BufferedReader br = new BufferedReader(strReader);
                        String strLine = null;
                        while((strLine=br.readLine())!=null)
                             System.out.println(strLine);
                   }     //end of while loop
              }     //end of try
              catch (Exception e)
                   System.out.println("REPORT DELETION ::: EXCEPTION---" + e.getMessage());
                   conn.close();
         }     //end of main
    }     //end of ClassReportDeleteDaemon
    But it is giving the error "BAD OPTION -print|xargs". The command run well in shell.
    Please help.
    Thanking u.......

    Since the pipe '|' is interpreted by the shell then you need the shell to invoke your command
            String[] command = {"sh","-c","find /tmp/reports1 -name " + "\"" + "*" + "\"" + " -mtime +" + strdaysback + " -print|xargs rm -r"};
            final Process process = Runtime.getRuntime().exec(command);
      You should also read http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html at least twice and implement the recommendation regarding stdout and stderr.
    P.S. Why are you not using Java to find and delete these files?
    Message was edited by:
    sabre150

  • Run a Program Through my java program

    Good day to you :)
    I am wondering if there is anyway for me to run an executable (or batch) file though a program I made.
    Thank you :)

    Found it. thanks anyway :)

Maybe you are looking for

  • How do I install Snow Leopard from grey screen?

    I have an iMac that went to a grey screen.  I could not veryify or repair HD - had to erase (repaird and verified HD after erase).  Tried to reinstall Snow Leopard.  However, in order to get to the install screen, I have to reboot several times.  Whe

  • I removed my "settings" icon

    while trying to jailbreak my ipod touch i some how ereased my settings app alonge with music,itunes store, app store, browser, contacts, and a few other things. i've been looking for solutions ALL day and have found nothing! PLEASE HELP!!!    

  • TS1424 Downloading software update unsuccessfully on iphone 4 for over a year. Error 9006 appeared this time!!

    I have been trying to update the software on my iphone 4 forever. Today at least I got an error message (9006). Any ideas?

  • Create invoice

    I want creating an invoice to receive "sales revenue received in advance" before issue goods to customer. How can i do it ?

  • Does System Centre detect Dyre Malware?

    Hello, Dyre, a piece of malware known for pursuing banking credentials, looks to have recently added Salesforce credentials to its list of targets. Can anyone please, whether System Centre 2012 can deal with this or no ? Thanks Tushar