How to use 'bash' command in java?

Hi,
I am using Linux operating system
when i run the following code, 'test.sh' not started
================================================================
String cmd = "bash \"/home/kulandaivelu/Desktop/works/other's works/test.sh\"";
Runtime.getRuntime().exec(cmd).waitFor();
================================================================
but it started when i use same command(bash "/home/kulandaivelu/Desktop/works/other's works/test.sh") in terminal
anyone let me know what mistake i made in the code piece..
Thanks in Advance
Kulandaivelu

Hi,
thanks a lot..
I used the following code.. it worked well..
===============================================================
String cmd[] = {"bash","/home/kulandaivelu/Desktop/works other's/test.sh"};
Runtime.getRuntime().exec(cmd).waitFor();
===============================================================
Thanks a lot again..

Similar Messages

  • How to execute Linux command from Java app.

    Hi all,
    Could anyone show me how to execute Linux command from Java app. For example, I have the need to execute the "ls" command from my Java app (which is running on the Linux machine), how should I write the codes?
    Thanks a lot,

    You can use "built-in" shell commands, you just need to invoke the shell and tell it to run the command. See the -c switch in the man page for your shell. But, "ls" isn't built-in anyays.
    If you use exec, you will want to set the directory with the dir argument to exec, or add it to the command or cmdarray. See the API for the variants of java.lang.Runtime.exec(). (If you're invoking it repeatedly, you can most likely modify a cmdarray more efficiently than having exec() decompose your command).
    You will also definitely want to save the returned Process and read the output from it (possibly stderr too and get an exit status). See API for java.lang.Process. Here's an example
    java.io.BufferedReader br =
    new java.io.BufferedReader(new java.io.InputStreamReader(
    Runtime.getRuntime().exec ("/sbin/ifconfig ppp0").
    getInputStream()));
    while ((s = br.readLine()) != null) {...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to call gnuplot command from java

    Hi there,
    In our course, we are required to develop an GUI for gnuplot. In case you don't know about gnuplot, it's a plotting program and has lots of command. We want to use java and swing, but now we don't know how to call gnuplot command from java, or how to execute a shell command(script) from java.
    By the way, since we need read in files with several columns of data and allow user to select a column, we want to use JTable. Is that reasonable?
    Thanks a lot for any suggestions!
    Jack

    Hi, there:
    Will using JTable add much overhead? I may have to use several JTables and switch among them. I can add scroll bar to or edit JTables, right?
    BTW, do you have experience about gnuplot? Can I find the command tree of gnuplot somewhere? Or do you know a better place to post question about gnuplot? unix/linux group, maybe.
    Thanks,
    Jack
    P.S. Would you guys answer my question after I use up my duke dollars? :- )

  • How to use sql query in java ?

    i don't know how to use sql query in java code.
    who can give me some advice?
    thanks

    http://java.sun.com/developer/onlineTraining/Database/JDBC20Intro/

  • How to use Thread.sleep() with Java Berkeley Base API?

    Hi,
    I have explained the weird problem about the server was too busy to response to SSH but it continued to finish to run (Server not response when inserting millions of records using Java Base API
    Even I tried to increase CachSize and renice Java program, but it did not work. So, I am thinking to set sleeping time for threads in Java Berkeley Base API (using “ps” command, there were 18 light weight processes created). My program did not implement transaction or concurrency because it simply creates (millions) databases records only. Is it possible and correct to do like this in the code:
    try{
    //do create a db record
    Thread.currentThread().sleep(1000);//sleep for 1000 ms
    catch(ItrerruptedException ie){
    Thank you for your kindly suggestion.
    Nattiya

    where can I get the help doc about use AT commands in java.
    Can you give me some code example about this. It is
    difficulty to me to write it myself.You simply have to send the characters and receive the characters via the comm extension. Here is the ITU standard command set - http://ridge.trideja.com/wireless/atcommands/v250.pdf. Various modems and other devices extend this in a number of ways, you may need to find documentation specific to your device as well. But start with the standard.

  • How to use bash within sqlplus?

    How to use bash within sqlplus?
    meaning I am doing something like this to look for files within a particular directory with some condition.
    N=0
    for i in $(find . -path \*/waiting/* -type f -not -name "SS*" -mmin +120 -print) ; do
    testarray[$N]="$i"
    echo "$i"
    let "N= $N + 1"
    done
    Output from above script is as follows:
    /d1/d2/d3/d4/waiting/abcd.txt
    /d1/d2/d31/d42/waiting/pqrs.txt
    /d1/d2/d32/d43/waiting/xyz.txt
    And now I want to input this data into database with help of insert.
    and here is the little pl/sql block to insert the data with looping thing.
    sqlplus $CONNECT <<-EOF
    DECLARE
    Counter integer :=1;
    BEGIN
    WHILE Counter <= ${no_of_files} LOOP
    INSERT INTO stuck_files(COL_DATE,SER_NAME,TYPE_FILE,FILENAME,FILE_STATUS) VALUES (sysdate,'pqrs','pqrs','pqrs','pqrs');
    Counter := Counter + 1;
    END LOOP;
    END;
    commit;
    exit;
    EOF
    Mapping is as follows:
    COL_DATE,SER_NAME,TYPE_FILE,FILEFILENAME,FILE_STATUS
    sysdate,d3,d4,abcd.txt,waiting
    sysdate,d31,d42,pqrs.txt,waiting
    sysdate,d32,d3,xyz.txt,waiting
    any idea how to do that?
    Edited by: user9274197 on Apr 28, 2013 5:09 PM

    user9274197 wrote:
    How to use bash within sqlplus?
    meaning I am doing something like this to look for files within a particular directory with some condition.
    N=0
    for i in $(find . -path \*/waiting/* -type f -not -name "SS*" -mmin +120 -print) ; do
    testarray[$N]="$i"
    echo "$i"
    let "N= $N + 1"
    done
    Output from above script is as follows:
    /d1/d2/d3/d4/waiting/abcd.txt
    /d1/d2/d31/d42/waiting/pqrs.txt
    /d1/d2/d32/d43/waiting/xyz.txt
    And now I want to input this data into database with help of insert.
    and here is the little pl/sql block to insert the data with looping thing.
    sqlplus $CONNECT <<-EOF
    DECLARE
    Counter integer :=1;
    BEGIN
    WHILE Counter <= ${no_of_files} LOOP
    INSERT INTO stuck_files(COL_DATE,SER_NAME,TYPE_FILE,FILENAME,FILE_STATUS) VALUES (sysdate,'pqrs','pqrs','pqrs','pqrs');
    Counter := Counter + 1;
    END LOOP;
    END;
    commit;
    exit;
    EOF
    Mapping is as follows:
    COL_DATE,SER_NAME,TYPE_FILE,FILEFILENAME,FILE_STATUS
    sysdate,d3,d4,abcd.txt,waiting
    sysdate,d31,d42,pqrs.txt,waiting
    sysdate,d32,d3,xyz.txt,waiting
    any idea how to do that?
    Edited by: user9274197 on Apr 28, 2013 5:09 PMhttp://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:439619916584
    Cheers,

  • How to use C-Structure in java applets

    hi alls,
    I want to use a struct model (struct in C++) in java applets. i know class is used in java applications. but, how can i convert in java applets?
    class renk
    int r;
    int gr;
    int b;
    import java.awt.Graphics;
    import java.awt.Color;
    import java.awt.Event;
    import java.applet.Applet;
    public class benek extends Applet
    final int n=10;
    int x[] = new int[n];
    int y[] = new int[n];
    int count = 0;
    renk clr[] = new renk[n];
    public void init()
    setBackground(Color.black);
    public boolean mouseDown(Event yordam, int xyer, int yyer)
    if (count<n)
    System.out.println("...");
    ekle(xyer,yyer);
    else System.out.println("Kapasite Doldu...");
    return true;
    void ekle(int xyer, int yyer)
    int r1 = (int)Math.floor(Math.random()*256);
    int gr1 = (int)Math.floor(Math.random()*256);
    int b1 = (int)Math.floor(Math.random()*256);
    clr[count].r = r1;
    clr[count].gr = gr1;
    clr[count].b = b1;
    x[count]=xyer;
    y[count]=yyer;
    count++;
    repaint();
    public void paint(Graphics g)
    it gives error message... how can � use struct model in java applets???
    if you help me i will be greatfull....

    � use import but it doesn't work.
    i add: import renk; or import class renk;
    how will � add import I assumed based on your initial post that the renk and benek classes were in the same file. Apparently you're saying they are not. So for another thing, make your renk class "public class renk", and add the "public" keyword to the 3 members of that class. Then if your code still doesn't see the "renk" class, it would just be that you don't have the directory that contains the compiled "renk.class" in your classpath.

  • How to use " toFront() " method in java application and in which package or

    How to use " toFront() " method in java application and in which package or class having this toFront() method.if anybody know pl. send example.

    The API documentation has a link at the top of every page that says "Index". If you follow that and look for toFront(), you will find it exists in java.awt.Window and javax.swing.JInternalFrame.
    To use it in a Java application, create an object x of either of those two classes and write "x.toFront();".

  • How to use XML / XPath in JAVA (in 1.4) which third part component to use?

    How to use XML / XPath in JAVA (in 1.4)
    I'm absolutely novice in XML
    but I need to query XML using XPath
    As I understand XPath become avalible only in Java 1.5
    But I use 1.4 (project requirement)
    Which third part component could you recomend?

    Can anyone help me with this XPath query
    I get result [title: null]
    import java.io.*;
    import javax.xml.parsers.*;
    import org.xml.sax.*;
    import org.w3c.dom.*;
    import org.jaxen.*;
    import org.jaxen.dom.*;
    import org.jaxen.saxpath.*;
    import java.util.*;
    public class TestX {
         public void ggg() {
              try {
                   File f = new File("journal.xml");
                   DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
                   org.w3c.dom.Document doc = docBuilder.parse(f);
                   XPath xpath = new DOMXPath( "/journal/article/title" );
                   List result = (List) xpath.evaluate(doc);
                   System.out.println(result.get(0));
              } catch (Exception e) {
                       e.printStackTrace();
         public static void main(String[] args) {
              TestX tx = new TestX();
              tx.ggg();
    }journal.xml
    <journal>
        <article id="article.1">
            <title>Art1</title>
            <author>
               <first>Bob</first>
               <last>McWhirter</last>
            </author>
            <text>
            </text>
        </article>
        <article id="article.2">
            <title>Art2</title>
            <author>
               <first>James</first>
               <last>Strachan</last>
            </author>
            <text>
            </text>
        </article>
    </journal>

  • How to use openjpa  + kodo in Java SE?

    Hi.
    We are developing J2EE application on Weblogic Server 9. For a part of application we should create unit tests that will be run in Java SE. How to use openjpa + kodo in Java SE?

    Hi,
    Try the EclipseLink JPA JEE5/JEE6 provider - it has been shipping as part of WebLogic Server since 10.3.1.0.
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    The following page has several SE, application-managed and container-managed EE example tutorials with source.
    http://wiki.eclipse.org/EclipseLink/Examples/JPA/WebLogic_Web_Tutorial
    http://wiki.eclipse.org/EclipseLink/Examples/JPA
    The following forum will help you with any JPA specific issues.
    Forum: TopLink/JPA
    TopLink/JPA
    thank you
    /michael
    http://www.eclipselink.org

  • How to use STSADM commands in sharepoint 2007

    How to use STSADM commands in sharepoint 2007

    Hi,
    There is no such STSADM commands to get the user groups.  There are two separate STSADM commands get either users or groups for particular site.
    STSADM -o enumusers <<url>>
    STSADM -o enumgroups <url>
    For complete reference, please refer to the following article.
    http://blogs.technet.com/b/josebda/archive/2008/03/15/complete-reference-of-all-stsadm-operations-with-parameters-in-moss-2007-sp1.aspx
    One such console application available to get the user groups.  Please refer to the below article.
    List all SharePoint groups a user belongs to
    Please don't forget to mark it as answered, if your problem resolved or helpful.

  • How to execute DOS command in Java?

    I want to execute a dos command in Java,such as execute test.bat command? How to realize it?
    Thanks in advance!

    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    I found this article really useful in solving this. Hope it helps.
    Cheers,
    John

  • How to Use Exec function in Java Code

    How to Use Exec method
    I want to Execute command
    net Start "some service"
    using exec method of runtime class
    or i use some other way if suggest

    Assuming you have read http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html#exec(java.lang.String) already, I can only suggest to be more specific in what your problems are. If you are after just some example code, then download ftp://ftp.ebi.ac.uk/pub/software/textmining/monq/monq.tar.gz and have a look at the source code of monq.stuff.Exec. It does all those things which are necessary to keep track of a Process after it was created with exec.
    Harald.
    BioMed Information Extraction: http://www.ebi.ac.uk/Rebholz-srv/whatizit

  • How to Use native keyword in java programming

    Hi ,
    I am using JDK 1.6.0_11 , and i was trying to create a java program using "native" keyword ,
    i got the sample code for the same from the site : - http://www.javaworld.com/javaworld/javatips/jw-javatip23.html
    But when i type this command " C:\javah -stubs Happy " following error occurs
    " Error: JNI does not require stubs, please refer to the JNI documentation. "
    then typed " c:\javah -jni Happy" without any error .
    After that i wrote a HappyImpl.c as mentioned in the above tutorial
    #include <StubPreamble.h> /* Standard native method stuff. */
    #include "Happy.h" /* Generated earlier. */
    #include &ltstdio.h> /* Standard C IO stuff. */
    void Happy_printText (struct HHappy *this)
    puts ("Happy New Year!!!");
    then it is not compling and error is
    "unable to open included file StubPreamble.h file
    unable to open included file Happy.h file "
    Please help me . i want to use native method , i did exactly the same in tutorial at above link.
    Thanks & Regards
    Mannat

    you do need to know how to use your C compiler... It quite clearly can't find those files which indicates that you didn't tell it where to find them.

  • How to execute MySqlDump Command from java..........

    hi friends,Iam used mysqldump command in linux platform to take backup of the database,its work properly....the command am used is
    mysqldump -u root -p threadpool > sampledatabase.sql
    I need to execute the same command in java....?Anyone here to know how to do that....?Thanks in advance........

    Crosspost:
    http://forum.java.sun.com/thread.jspa?threadID=5185230&messageID=9721722#9721722
    http://forum.java.sun.com/thread.jspa?threadID=5185199&messageID=9721587#9721587
    Do not mess the forum.

Maybe you are looking for