Click to See Complete Forum and Search --> : java Runtime question


Seko
01-05-2004, 04:10 PM
How can I execute "ln -s" command using Runtime.getRuntime.exec(); in java?

I can execute "ls" command and can get the output to the console but i cant find any way how to get the result of
"ln -s"

can anyone help??

bwkaz
01-05-2004, 09:09 PM
ln -s doesn't print anything if it succeeds.

According to the Java docs (linked off java.sun.com), how do you pass arguments to the program you exec? I'd suspect that Runtime.exec() won't split out its argument; you might have to pass another argument (an array of strings that are the arguments).

mwinterberg
01-05-2004, 09:21 PM
Edit: ^^ exec() will parse it's string using StringTokenizer's standard constructor (parsing on whitespace)

Can you post the code snippet? If there is any whitespace in the filenames you're passing to ln, then you'll probably want to use this version of exec():
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html#exec(java.lang.String[])

You may also want to get the error stream from the process, and print that out, as well.

Edit: Additional note, you can use the exitValue() function as well, to detect situations that bwkaz mentioned if there's no output:
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Process.html#exitValue()


-Michael

Seko
01-06-2004, 04:19 AM
Thanks for answers, I solve the problem.
Runtime.getRuntime().exec("ln -s a.txt a") works fine