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 / April 2007

Tip: Looking for answers? Try searching our database.

Runtime.exec

Thread view: 
micro - 18 Apr 2007 06:09 GMT
hi all,
I use java in windows xp and I want to execute  .jar files in my java
program i tried the next code but it didn't work.
no errors in compilation,and no exception when I run it ,yet my
des.jar file didn't run.

public class RunIt {
    public static void main(String args[]){
        String[] commands=new String[3];
        commands[0]="cmd.exe";
        commands[1]="cd C:\\Documents and Settings\\ASUS\\Desktop";
        commands[2]="java -jar des.jar";

        try {
            Runtime.getRuntime().exec(commands);

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}

although when I try: "java -jar des.jar" in the command line it works
fine
Gordon Beaton - 18 Apr 2007 07:03 GMT
>         commands[0]="cmd.exe";
>         commands[1]="cd C:\\Documents and Settings\\ASUS\\Desktop";
>         commands[2]="java -jar des.jar";

The command array you pass to Runtime.exec() should hold exactly *one*
command, not a series of them.

If you want to run the command from a specific directory, there is a
version of Runtime.exec() that lets you specify a working directory.

/gordon

--
micro - 18 Apr 2007 07:30 GMT
> The command array you pass to Runtime.exec() should hold exactly *one*
> command, not a series of them.
[quoted text clipped - 5 lines]
>
> --
thank a lot for your valuable help.
solved
Process p=Runtime.getRuntime().exec("java -jar des.jar",null,new
File("C:\\Documents and Settings\\ASUS\\Desktop"));


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.