Directory Question

I am trying to run a system call from a specified directory and it doesn't seem to be working. The call itself just renames a Rational/IBM database replica called a VOB.

The command has to be run in this directory:

M:\SiteA_VIEW\SiteA_VOB

The actual command is something like:

multitool rename replica:SiteA SiteB

In the above SiteA is the original name of the replica and SiteB is what I want to change the name too.

I am using Java Swing and Netbeans 5.5.1 and the code is below.

privatevoid btn_RenameActionPerformed(java.awt.event.ActionEvent evt){

// TODO add your handling code here:

String VOBpath =null;

String CReplica =null;

String NReplica =null;

VOBpath = txt_VOBpath.getText();

CReplica = txt_Currentrepname.getText();

NReplica = txt_Newrepname.getText();

String command = (VOBpath +" cmd /c multitool rename replica:" + CReplica +" "+ NReplica);

StringBuffer sb =new StringBuffer();

Process p =null;

try{

p = Runtime.getRuntime().exec(command);

}catch (IOException ex){

ex.printStackTrace();

}

}

txt_VOBpath holds the path of the directory that the command needs to be run from

txt_Currentrepname holds the original name of the VOB

txt_Newrepname holds the new name of the VOB

When I run the debugger the String command is equal to:

M:\SiteA_VIEW\SiteA_VOB cmd /c multitool rename replica:SiteA SiteB

Anyone have any ideas as to what could be wrong?

Thanks

[2106 byte] By [yelllow4ua] at [2007-11-27 10:14:07]
# 1

So does anyone know if this is the correct syntax?

VOBpath + " cmd /c multitool rename replica:" + CReplica + " "+ NReplica

If I need to run this command from a certain directory is it correct to place the path string (in this case the path is stored in VOBpath) in front of the system command (i.e, VOBpath + System Command)?

Or do I need to do something else?

yelllow4ua at 2007-7-28 15:31:17 > top of Java-index,Java Essentials,New To Java...
# 2

Looks to me like th exec string is incorrect:

M:\SiteA_VIEW\SiteA_VOB cmd /c multitool rename replica:SiteA Site

Do you not want something like:

[path to multi tool directory]/multitool rename replica:SiteA SiteB

?

bryanoa at 2007-7-28 15:31:17 > top of Java-index,Java Essentials,New To Java...
# 3

Don't I need the "cmd /c" in front of the system call?

yelllow4ua at 2007-7-28 15:31:17 > top of Java-index,Java Essentials,New To Java...
# 4

NO, you don't.

When you put "cmd /c" your calling cmd to handle your command, and you dont' need this.

The problem with you directory can be easily solved with

Runtime.exec(String[] cmdarray, String[] envp, File dir)

Hope I helped

pbulgarellia at 2007-7-28 15:31:17 > top of Java-index,Java Essentials,New To Java...
# 5

Never used this before:

Runtime.exec(String[] cmdarray, String[] envp, File dir)

What is the String[] envp?

How would the syntax go? Something like this...

String CReplica = txt_Currentrepname.getText();

String NReplica = txt_Newrepname.getText();

String VOBpath = txt_VOBpath.getText();

String cmdarray[] = ("multitool rename replica:" + CReplica + " "+ NReplica");

Runtime.exec(String[] cmdarray, String[] envp, VOBpath);

yelllow4ua at 2007-7-28 15:31:17 > top of Java-index,Java Essentials,New To Java...
# 6

I'm just bumping the thread to see if anyone else has any input. I still can't get this to work. Thanks.

yelllow4ua at 2007-7-28 15:31:17 > top of Java-index,Java Essentials,New To Java...