Problem with Runtime.getRuntime().exec()

Discussion in 'Java' started by Rohit Gupta, Jun 16, 2005.

  1. Rohit Gupta

    Rohit Gupta Guest

    I have faced a certain problem while writing the following code to
    run a shell command through a Java Program....

    The code is...

    { public static void termFrequencyVector() throws IOException
    {
    //String str1 = "man ls>test.txt";
    //Process p = Runtime.getRuntime().exec(str1);
    Runtime rt = Runtime.getRuntime();
    String[] envp = { "PATH=/fs11/bt2003/ankans" };
    Process p = rt.exec("ls", envp);
    //String str1 = "ls>test.txt";
    //Process p = Runtime.getRuntime().exec(str1);
    }

    public static void main(String [] args) throws Exception
    {
    termFrequencyVector();
    }
    }


    I get the following error after the code compiles correctly...

    Exception in thread "main" java.io.IOException: No such file or
    directory
    at java.lang.ConcreteProcess.startProcess(java.lang.String[],
    java.lang.String[], java.io.File) (/usr/lib/libgcj.so.5.0.0)
    at java.lang.ConcreteProcess.ConcreteProcess(java.lang.String[],
    java.lang.String[], java.io.File) (/usr/lib/libgcj.so.5.0.0)
    at java.lang.Runtime.execInternal(java.lang.String[],
    java.lang.String[], java.io.File) (/usr/lib/libgcj.so.5.0.0)
    at java.lang.Runtime.exec(java.lang.String[], java.lang.String[],
    java.io.File) (/usr/lib/libgcj.so.5.0.0)
    at java.lang.Runtime.exec(java.lang.String, java.lang.String[],
    java.io.File) (/usr/lib/libgcj.so.5.0.0)
    at java.lang.Runtime.exec(java.lang.String, java.lang.String[])
    (/usr/lib/libgcj.so.5.0.0)
    at TFIDF.termFrequencyVector() (Unknown Source)
    at TFIDF.main(java.lang.String[]) (Unknown Source)


    Please tell me whether it is possible to run commands like ls in this
    way or am I writing the path name environment or command name wrong? I
    dont think there is any mistake in the syntax of the code.
    Rohit
     
    Rohit Gupta, Jun 16, 2005
    #1
    1. Advertising

  2. "Rohit Gupta" <> schrieb im Newsbeitrag
    news:...
    >
    > I have faced a certain problem while writing the following code to
    > run a shell command through a Java Program....


    You should read this article
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html . It
    explains how to run shell commands under Windows (Listing 4.5
    GoodWindowsExec.java). I think the explained problem applies to Linux, too.

    Regards
    Sebastian
     
    Sebastian Scheid, Jun 16, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Zsolt Koppany
    Replies:
    2
    Views:
    7,303
    SaintMagoo
    Mar 5, 2011
  2. S!mb@
    Replies:
    3
    Views:
    7,744
    Roedy Green
    Jul 19, 2004
  3. Mao
    Replies:
    2
    Views:
    3,148
  4. Dave Neuendorf
    Replies:
    5
    Views:
    6,788
    Anthony Borla
    Feb 25, 2005
  5. bugbear
    Replies:
    1
    Views:
    1,091
    bugbear
    Nov 4, 2005
Loading...

Share This Page