Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2005

Tip: Looking for answers? Try searching our database.

Problem with Runtime.getRuntime().exec()

Thread view: 
Rohit Gupta - 16 Jun 2005 14:42 GMT
 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
Sebastian Scheid - 16 Jun 2005 15:22 GMT
>  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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.