Running Files

I am trying to run a an excel file using the following commandRuntime r=Runtime.getRuntime;Process pr = r.exec("cmd.exe /c Start");But It always starts up at the same directory. I need it to change directories and run the excel file at the same time.
[278 byte] By [krwhale78a] at [2007-11-27 9:34:33]
# 1
Why can you not specify the full path of the Excel file that you wish to launch rather than change directory?
_helloWorld_a at 2007-7-12 22:59:06 > top of Java-index,Java Essentials,Java Programming...
# 2
One of the exec() methods lets you specify the initial working directory, I believe. Check the docs.
paulcwa at 2007-7-12 22:59:06 > top of Java-index,Java Essentials,Java Programming...
# 3
How do you use the execs that allow you to change directories?
krwhale78a at 2007-7-12 22:59:06 > top of Java-index,Java Essentials,Java Programming...
# 4

You just call it.

exec

public Process exec(String[] cmdarray,

String[] envp,

File dir)

throws IOException

Executes the specified command and arguments in a separate process with the specified environment and working directory.

Given an array of strings cmdarray, representing the tokens of a command line, and an array of strings envp, representing "environment" variable settings, this method creates a new process in which to execute the specified command.

That's what the docs say.

You don't "change the directory" like you when you call "cd" from the shell. You just tell it what directory to start in.

paulcwa at 2007-7-12 22:59:06 > top of Java-index,Java Essentials,Java Programming...
# 5
What are the tokens of a command line.
krwhale78a at 2007-7-12 22:59:07 > top of Java-index,Java Essentials,Java Programming...
# 6

They just mean the program name and the arguments.

So where you might do "cmd.exe /c Start SomeFile", then the tokens are "cmd.exe", "/c", "Start", "SomeFile".

Another version of exec() lets you use one big string (in which case the string is tokenized over whitespace) and also specify the working directory.

Again: read the docs.

paulcwa at 2007-7-12 22:59:07 > top of Java-index,Java Essentials,Java Programming...
# 7
Thank you. I finally figured it out.
krwhale78a at 2007-7-12 22:59:07 > top of Java-index,Java Essentials,Java Programming...